【问题标题】:Alexa is not returning the numbers and calculation in the response, only the text?Alexa 没有返回响应中的数字和计算,只返回文本?
【发布时间】:2020-10-12 13:38:00
【问题描述】:

我正在学习如何使用 Alexa 开发技能。我遵循 Lynda 课程来建立我的计算器技能,但是遇到了一个问题,即没有返回数字和结果。我仔细检查了我的代码,并在 Echoism.io 上进行了尝试,同样的问题。 根据附件,数字记录在 JSON 输入中,但没有在 SpeechText 或 displayText 中返回?

缺少的代码是什么?谢谢。

Node.js code Alexa console JSON Input

【问题讨论】:

    标签: node.js alexa-skills-kit alexa-voice-service alexa-app


    【解决方案1】:

    欢迎罗伊!夫妇的事情。以后只需将您的代码直接放在页面上,这样它就可以被搜索到,我们可以看到您正在使用的确切字符。

    通过查看图像,在我看来,以下可能是您对模板文字的使用。超级常见的错误。

    所以要使用template literals,您需要使用反引号 (`) 而不是单引号 (')

    看起来是你目前拥有的

    speechText = 'The result of ${firstNumber} plus ${secondNumber} is ${result}';
    

    而你想要的是

    speechText = `The result of ${firstNumber} plus ${secondNumber} is ${result}`;
    

    这是另一个很好的资源:

    How to interpolate variables in strings in JavaScript, without concatenation?

    【讨论】:

    • 感谢您的反馈!下次我会尝试将代码剪切并粘贴到正文中。不知道反勾号是一回事。它奏效了。
    猜你喜欢
    • 1970-01-01
    • 2020-10-15
    • 2011-08-22
    • 2019-10-28
    • 2019-10-14
    • 1970-01-01
    • 2012-10-27
    • 2019-03-15
    • 1970-01-01
    相关资源
    最近更新 更多