Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 和Alexa一起数_Node.js_Loops_Count_Alexa_Translate - Fatal编程技术网

Node.js 和Alexa一起数

Node.js 和Alexa一起数,node.js,loops,count,alexa,translate,Node.js,Loops,Count,Alexa,Translate,我正在尝试写一个Alexa意图,它将以西班牙语计算用户给定的英语数字。我可以让Alexa用西班牙语说出正确的数字,但我在想如何让她说出不止一个数字时遇到了麻烦 这是我的密码: const numbers = { 'Zero':'Cero', 'One': 'Uno', 'Two' : 'Dos', 'Three': 'Tres' } const CountUpToIntentHandler = { canHandle(ha

我正在尝试写一个Alexa意图,它将以西班牙语计算用户给定的英语数字。我可以让Alexa用西班牙语说出正确的数字,但我在想如何让她说出不止一个数字时遇到了麻烦

这是我的密码:

    const numbers = {
    'Zero':'Cero',
    'One': 'Uno',
    'Two' : 'Dos',
    'Three': 'Tres'    
    }

    const CountUpToIntentHandler = {
    canHandle(handlerInput) {
        return handlerInput.requestEnvelope.request.type === 'IntentRequest'
            && handlerInput.requestEnvelope.request.intent.name === 'CountUpToIntent';
    },

    handle(handlerInput) {
        const numberToCountTo = 
handlerInput.requestEnvelope.request.intent.slots.numberr.resolutions.resolutionsPerAuthority[0].values[0].value.name;
        const speechOutput = [];
        while (allTheNumbers !== 'Zero') {
            var allTheNumbers = numbers[numberToCountTo];    
            speechOutput.push(allTheNumbers--);
        }

        return handlerInput.responseBuilder
        .speak(speechOutput)
        .reprompt(speechOutput)
        .getResponse();
    }
    };
有人能帮我正确地写循环吗,所以Alexa说了不止一个数字


谢谢

我认为你做得不对,你在比较所有的数字变量,甚至没有声明它。解决这个问题的一种方法是,使用数字槽,当用户说出某个数字时,用给定的数字循环。并检查给定的数字以便于比较

const numbers = {
    '1':'Cero',
    '2':'Uno',
    '3':'Dos',
    '4':'Tres'    
    }

我认为您的做法是错误的,您正在比较
所有的数字
变量,甚至没有声明它。解决这个问题的一种方法是,使用数字槽,当用户说出某个数字时,用给定的数字循环。并检查给定的数字以便于比较

const numbers = {
    '1':'Cero',
    '2':'Uno',
    '3':'Dos',
    '4':'Tres'    
    }
如果你使用英语,你可以很容易地说另一种语言

因此,您必须使用简单的for循环构建响应,而无需转换表,例如:

speech = "<speak><lang xml:lang='es-ES'>"

for(var i = 0; i < numberToCountTo; i++)
    speech += " " + i + " ";

speech += "</lang></speak>"

speech=“”
对于(变量i=0;i
如果使用,您可以轻松地用另一种语言说话

因此,您必须使用简单的for循环构建响应,而无需转换表,例如:

speech = "<speak><lang xml:lang='es-ES'>"

for(var i = 0; i < numberToCountTo; i++)
    speech += " " + i + " ";

speech += "</lang></speak>"

speech=“”
对于(变量i=0;i
您测试过了吗?是的,两个建议都不起作用。我还在试着编写代码。你测试过了吗?是的,两个建议都不起作用。我还在试着找出密码。