Как отобразить информацию в цикле for?
Я использую Google Dialogflow, отображающий намерение с помощью метода функции, и проверяю, подходит ли комната на основе вместимости и цены. диапазон, который находится в базе данных реального времени firebase, которую я настроил.
Цикл for должен проверять каждую комнату и оператор if-else для запуска, если требования выполнены или нет.
Console.log работает, но теперь я хочу отобразить названия подходящих комнат (app.add), как мне это сделать?
const ROOM_RECOMMENDATION = 'request_roomRecommendation';
function recommendRooms(app) {
let roomCapacity = parameter.roomCapacity;
let roomPriceRange = parameter.roomPriceRange;
var ref = database.ref().child('rooms');
ref.once('value').then(function (snapshot) { /*Not adding return b4 hand cause got some issues with the asynchronisation*/
console.log("comehere2");
/*Get all information from the firebase rooms thing*/
var roomInformation = snapshot.val();
/*For loop to continuos display rooms that meet the requirements based on Capacity and Price Range requirement*/
for (var roomTypes in roomInformation) {
/*Console log to check if the values arrived*/
console.log("Name of Room: " + roomTypes + "Room Capacity: " + roomInformation[roomTypes]['roomCapacity'] + "Room Price Range: " + roomInformation[roomTypes]['roomPriceRange']);
/*Check if the room type meet the requirements */
if (roomInformation[roomTypes]['roomCapacity'] == roomCapacity && roomInformation[roomTypes]['roomCapacity'] <= 5 && roomInformation[roomTypes]['roomPriceRange'] == roomPriceRange) {
console.log("The rooms that meet requirement are: " + roomTypes);
app.add("Unfort");
}
else if (roomInformation[roomTypes]['roomCapacity'] > 5) {
app.add("Unfortunately all our rooms for above 5 are all in the high price ranges. Would you like to consder viewing all the rooms and consider reserving 2 rooms instead?");
}
}
app.add("done");
});
actionMap.set(ROOM_RECOMMENDATION, recommendRooms);