Alexa: Невозможно изменить множественное число на единственное - PullRequest
0 голосов
/ 10 сентября 2018

Попытка изменить слово - попытка попробовать навык викторины Alexa. В настоящее время, если вы получите правильный ответ, он скажет, что вы угадали его в 1 попытке. Я хочу сказать, что вы правильно догадались с 1 попытки.

function pluralize(count, singular, plural) {
  if(count === 1) {
    return `${count} ${singular}`;
  } else {
    return `${count} ${plural}`;
  }
}

добавил функцию к этой строке в AnswerIntent

var speech = "<audio src='https://s3.amazonaws.com/ask-soundlibrary/ui/gameshow/amzn_ui_sfx_gameshow_tally_positive_01.mp3'/>Well done, you have guessed it right in " + (4-count) + " ${pluralize(count, `attempt`, `attempts`)}. Your score is " + score + " . Do you wish to play again? say Yes to play again and No to quit.";

но результат

Молодец, вы догадались прямо в 3. Ваш счет 8. Вы хотите играть снова? скажите «да», чтобы снова играть, и «нет», чтобы выйти.

полный код AnswerIntent

"AnswerIntent" : function(){
        var guess = this.event.request.intent.slots.Guess.value;
        var l1 = this.event.request.intent.slots.LetterOne.value;
        var l2 = this.event.request.intent.slots.LetterTwo.value;
        var l3 = this.event.request.intent.slots.LetterThree.value;
        var l4 = this.event.request.intent.slots.LetterFour.value;
        var index = this.attributes.Game.index;
        var count = this.attributes.Game.count;
        var answer = arr[index].A;
        var a = answer.split('');
        if(guess !== undefined && l1 !== undefined && l2 !== undefined && l3 !== undefined && l4 !== undefined){
            l1 = l1.toLowerCase();
            l2 = l2.toLowerCase();
            l3 = l3.toLowerCase();
            l4 = l4.toLowerCase();
            if(guess === answer && (l1 === a[0] || l1 === a[0] + ".") && (l2 === a[1] || l2 === a[1] + ".") && (l3 === a[2] || l3 === a[2] + ".") && (l4 === a[3] || l4 === a[3] + ".") ){
                this.attributes.Game.score += 1;
                var score = this.attributes.Game.score;
                **var speech = "<audio src='https://s3.amazonaws.com/ask-soundlibrary/ui/gameshow/amzn_ui_sfx_gameshow_tally_positive_01.mp3'/>Well done, you have guessed it right in " + (4-count) + " ${pluralize(count, `attempt`, `attempts`)}. Your score is " + score + " . Do you wish to play again? say Yes to play again and No to quit.";**

                this.emit(":askWithCard",speech,speech, "Well done", "your Score is " + score + ". To play again say, YES or to quit say, NO");
            }else{
                this.attributes.Game.count -= 1;
                count = this.attributes.Game.count;
                var question = arr[index].Q;
                var q = "<break time='0.5s'/>" + question.split('').join("<break time='0.5s'/>") + "<break time='0.5s'/>";
                if(count > 0){
                    var speech1 = "<audio src='https://s3.amazonaws.com/ask-soundlibrary/ui/gameshow/amzn_ui_sfx_gameshow_tally_negative_01.mp3'/> Please try again, your jumbled letters were " + q + ". You have " + count + " ${pluralize(attempts, `attempt`, `attempts`)}";
                    this.emit(":askWithCard",speech1,speech1,"Attempts Left: " + count, " Try again, your guess " + l1 + " "+ l2 + " "+l3 + " "+ l4 + " " + guess + " is incorrect");
                }else{
                    var ans = "<break time='0.5s'/>" + answer.split('').join("<break time='0.5s'/>") + "<break time='0.5s'/>";
                    var speech2 = "<audio src='https://s3.amazonaws.com/ask-soundlibrary/ui/gameshow/amzn_ui_sfx_gameshow_tally_negative_01.mp3'/> Sorry, there are no attempts left, the correct animal is " + ans + answer + ". Do you wish to play again? say Yes to play again and No to quit";
                    this.emit(":askWithCard",speech2,speech2,"NO MORE ATTEMPTS LEFT", "The correct animal is " + answer);
                }
            }
        }else{
            this.emit(":askWithCard","Please guess by spelling out the animal","Please guess by spelling out the animal","Please Spell the Animal","The guess should have the letters spelled out in the right order, followed by the name of the animal after that");
        }
    },

1 Ответ

0 голосов
/ 29 ноября 2018

Шаблонные литералы должны быть внутри обратных кавычек.В вашей строке кода вы смешиваете обратные кавычки с двойными кавычками, и это может быть проблемой.Попробуйте это:

var speech = `<audio src='https://s3.amazonaws.com/ask-soundlibrary/ui/gameshow/amzn_ui_sfx_gameshow_tally_positive_01.mp3'/>Well done, you have guessed it right in ${pluralize(count, 'attempt', 'attempts')}. Your score is ${score} Do you wish to play again? say Yes to play again and No to quit.`
...