node.js - 使用 Alexa 计数

标签 node.js loops count alexa translate

我正在尝试编写一个 Alexa intent ,该 intent 将计算用户用西类牙语给出的英文号码。我可以让 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 说出多个数字吗?

谢谢

最佳答案

我认为您的做法是错误的,您正在比较 allTheNumbers 变量,甚至没有声明它。解决这个问题的一种方法是获取数字槽,当用户说出某个数字时,然后用给定的数字循环它。并检查给定的数字进行比较,这样更容易。

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

关于node.js - 使用 Alexa 计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59439985/

相关文章:

javascript - 在使用 Quill.js 保存和重新加载数据时,我有哪些选择?

javascript - 如何让月份名称显示在循环返回中

python - 遍历字典值?

jquery - 向 jquery 计数器添加逗号

php mysql 计数

javascript - 在nodejs中使用exports返回一个值

android - 如果状态代码为 400 并在 android 中进行改造,则在响应错误主体上接收 NULL

javascript - Express 不加载 javascript 到客户端

javascript - 如何在 Angular 2中的模板 View 内进行嵌套循环

Unix 控制台 : Count distinct exceptions (not known beforehand)