Reputation: 23
const FactIntentHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return (request.type === 'IntentRequest' && request.intent.name === 'GetFactIntent');
//&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'GetFactIntent';
},
handle(handlerInput) {
var newFact = pitFile.facts[Math.floor(Math.random() * pitFile.fact.length)];//search for fact to return in random order 000561
var factResult = newFact.text; // store fact 000561
//speakoutput is a var and not a const because we want it to change 000561
var speakOutput = "Here's why we love pits:" + factResult;
return handlerInput.responseBuilder
.speak(speakOutput)
//.reprompt(speakOutput)
.getResponse();
}
};
This is my code, I am using the hello world template. I edited the built in helloworld intent but when I call the getfactintent I get an error message.
Upvotes: 2
Views: 1370
Reputation: 23
I have found the error, on line 8 the code var newFact = pitFile.facts[Math.floor(Math.random() * pitFile.fact.length)];//search for fact to return in random order 000561
"pitFile.fact.length" should actually be "pitFile.facts.length"
Upvotes: 0
Reputation: 1957
If this is an Alexa Hosted skill, try the CloudWatch link in the lower left of the code panel. The logs should contain an error message if there is one.
When you grab the random fact, you use an array "pitFile.fact", but get the length of "pitFile.facts" in the random number generation. One would think these should be the same.
Since they're not, you're probably getting an error that it "can't read property length of undefined" or that pitFile.fact is not an array. That would show up in the CloudWatch logs.
Upvotes: 1
Reputation: 2612
How did you asked? Real or via the "Test" tab in the skill console?
If real: Try to do the same in the skill console and test your skill. You will see a response and probably a more detailed error explanation in the JSON response on the right side.
Upvotes: 0