java script проблемы массива набора навыков Алекса - PullRequest
0 голосов
/ 07 июня 2018

Это мой javascript-код Alexa для программирования поваренной книги Alexa, где пользователи могут спрашивать о конкретных типах блюд.У меня есть массив со всеми именами блюд, и у них есть свойства, которые определены в массиве;название, тип диеты и тип питания (обед или ужин и т. д.).Однако, когда я пытаюсь вызвать еду, которая соответствует входным данным, которые дают пользователи, приравнивая varificFood / var foodType / var diet к оператору this.event.request.intent.slots.value, однако позже, когда я пытаюсь сопоставитьпри вводе свойств конкретного рецепта он говорит, что мои переменные (specificFood / foodType / diet) не определены.Почему это?

var recipe = [
{Name:'apple pie', Meal: 'dessert', Diet: 'vegetarian'},
{Name: 'rib eye steak', Meal: 'dinner', Diet:'meat'}
];

var handlers = {
    'LaunchRequest': function () {
     const speechOutput = OPENING_MESSAGE;
     this.response.cardRenderer(SKILL_NAME);
        this.response.speak(speechOutput).listen("I have opened the recipe book, ask me to find you a recipe if you would like!");
        this.emit(':responseReady');
        },
        'InitialIntent':function(){
          this.response.speak("Ok, I am finding you a recipe, is there a specific food you would like a recipe for? If so let me know what food it is, if instead you have no preference please also tell me!").listen();
          this.emit(':responseReady');
        },
        'specificRecipeIntent':function(){
         var specificfood = this.event.request.intent.slots.specificfood.value;
        this.response.speak("Ok, would you like a meat, pescetarian vegetarian, or vegan meal? If you have no preference say so!").listen();
    this.emit(':responseReady');
    },

        'dietaryPreferenceIntent':function(){
            var dietaryPreference = this.event.request.intent.slots.dietaryPreference.value;
            this.response.speak("Sounds good, will this meal be for breakfast, lunch, dinner, dessert or snack? Again if you have no preference let me know!").listen();
           this.emit(':responseReady');
        },
        'mealTimeIntent':function(){
          var mealTime = this.event.request.intent.slots.mealTime.value;
          this.response.speak("Awesome! I am going to go find you a recipe that matches all your requests").listen();
          this.emit(':responseReady');
        },

        'generateRecipeIntent':function(){
         var result = recipe.find(function( recipe ) { return recipe.Name == specificfood, recipe.Diet == dietaryPreference, recipe.Meal == mealTime });
        const speechOutputFinal = "Here is your final recipe " +  result + "  enjoy!";
        this.response.cardRenderer(SKILL_NAME);
        this.response.speak(speechOutputFinal);

        this.emit(':responseReady');
    },
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...