Hey guys,
i'm new to ask sdk v2 and got a question in understanding best practice for storing data:
I want to improve the behaviour of the "random quote" example skill so that there are no double quotes and Alexa states, that all quotes have been read aloud. My Code:
function randomQuote() { if (data.length !== 0) { // array not empty let randomNum = Math.floor(Math.random() * data.length); data.splice(randomNum, 1); // remove selected quote from array return data[randomNum]; } else { let finishedMessage = 'no more data'; data = refillArray; //refill the array return finishedMessage; } } const randomQuoteIntentHandler= { canHandle(handlerInput) { const request = handlerInput.requestEnvelope.request; return request.type === 'IntentRequest' && ( request.intent.name === 'randomQuoteIntent' || request.intent.name === 'AMAZON.StartOverIntent' || request.intent.name === 'AMAZON.YesIntent'); }, handle(handlerInput) { const speechText = randomQuote(); // random quote is called return handlerInput.responseBuilder .speak(`${speechText}`) .reprompt(`${speechText}`) .getResponse(); }, };
Unfortunately this code with calling the randomQuote function doesn't work properly. So there are still double quotes.
What is best practice for that kind of use case? Answers in pseudo code are also very welcome!
Thanks guys.