Search code examples
node.jsalexa-voice-servicealexa-skills-kit

Alexa is not returning the numbers and calculation in the response, only the text?


I am learning how to develop Skills with Alexa. I followed a Lynda course to build the My Calculator skill, however ran into a problem where the numbers and results are not returned. I double checked my code, and tried it on Echoism.io, and same problem. Per the attached, the numbers are recorded in the JSON input, however are not returned in the speechText or displayText?

What is the missing piece of code? Thanks.

Node.js code Alexa console JSON Input


Solution

  • Welcome Roy! Couple things. In the future just put your code right here on the page so that it becomes searchable and we can see the exact characters you are using.

    By looking at the images it looks like to me the following might be your use of template literals. Super common mistake.

    So to use template literals you need use the back tick (`) instead of the single quote (')

    It looks like it is that you currently have

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

    and what you want is

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

    Here is another good resources:

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