Javascript Alexa:无法将复数单词改为单数

Javascript Alexa:无法将复数单词改为单数,javascript,node.js,alexa,alexa-skills-kit,alexa-skill,Javascript,Node.js,Alexa,Alexa Skills Kit,Alexa Skill,尝试更改单词尝试尝试Alexa测验技能。目前,如果你得到了正确的答案,它会说你在1次尝试中猜对了。我想让它说你在一次尝试中猜对了 function pluralize(count, singular, plural) { if(count === 1) { return `${count} ${singular}`; } else { return `${count} ${plural}`; } } 将函数添加到AnswerIntent中的此行 var speech

尝试更改单词尝试尝试Alexa测验技能。目前,如果你得到了正确的答案,它会说你在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.";
"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");
        }
    },
var speech=“干得好,您在“+(4-count)+”${pluralize(count,`trunt`,`trunts`}中猜对了。您的分数是“+score+”。您想再玩一次吗?说“是”再玩一次,说“否”退出。”;
但结果是

干得好,你在3中猜对了。你的分数是8分。你想再玩一次吗?说“是”再玩一次,说“否”退出

回答意图的完整代码

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.";
"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");
        }
    },
“AnswerIntent”:函数(){
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指数=this.attributes.Game.index;
var count=this.attributes.Game.count;
var answer=arr[index].A;
var a=答案分割(“”);
如果(猜测!==未定义和&l1!==未定义和&l2!==未定义和&l3!==未定义和&l4!==未定义){
l1=l1.toLowerCase();
l2=l2.toLowerCase();
l3=l3.toLowerCase();
l4=l4.toLowerCase();
如果(猜测===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分数=this.attributes.Game.score;
**var speech=“干得好,你在“+(4-count)+”${pluralize(count,`trust`,`trusts`)}中猜对了。你的分数是“+score+”。你想再玩一次吗?说“是”再玩一次,说“否”退出。”**
这个.emit(“:askWithCard”,speech,speech,“干得好”,“你的分数是“+Score+”。再次玩时说“是”,或退出时说“否”);
}否则{
this.attributes.Game.count-=1;
count=this.attributes.Game.count;
var问题=arr[index].Q;
var q=“”+问题.拆分(“”).join(“”+“”);
如果(计数>0){
var speech1=“请再试一次,您的乱七八糟的字母是“+q+”。您有“+count+”${pluralize(尝试,`trust`,`trust`,`trusters`)}”;
这个.emit(“:askWithCard”,speech1,speech1,“尝试左:”+count,“重试,您的猜测“+l1+”+l2+”+l3+”+l4+“+guess+”不正确”);
}否则{
var ans=“”+回答.拆分(“”).join(“”+“”);
var speech2=“对不起,没有剩余的尝试,正确的动物是“+ans+回答+”。您想再次玩吗?说“是”重新玩,说“否”退出”;
这个.emit(“:askWithCard”,speech2,speech2,“不再尝试了”,“正确的动物是”+答案);
}
}
}否则{
这个.emit(“:askWithCard”,“请拼写动物来猜”,“请拼写动物来猜”,“请拼写动物”,“猜应该按照正确的顺序拼写字母,然后是动物的名称”);
}
},

模板文字必须位于背景标记内。在您的代码行中,您混合了反勾号和双引号,这可能就是问题所在。试试这个:

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.`
var speech=`做得好,您在${pluralize(count,'trunt','trunts')中猜对了。你的分数是${score}你想再玩一次吗?说“是”再玩一次,说“否”退出`