From efaea9e73f58c75b11163ebc861d0dbe6820b3b7 Mon Sep 17 00:00:00 2001 From: Patrick Mollohan Date: Sun, 23 Oct 2016 15:53:33 -0400 Subject: [PATCH] reindeerGames fixes Fixed warnings and missing semi-colons. Tweaked output text to increase readability in Alexa app. --- samples/reindeerGames/src/index.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/samples/reindeerGames/src/index.js b/samples/reindeerGames/src/index.js index d89f856..c6b7f76 100755 --- a/samples/reindeerGames/src/index.js +++ b/samples/reindeerGames/src/index.js @@ -399,12 +399,12 @@ function getWelcomeResponse(callback) { currentQuestionIndex = 0, spokenQuestion = Object.keys(questions[gameQuestions[currentQuestionIndex]])[0], - repromptText = "Question 1. " + spokenQuestion + " ", + repromptText = "\nQuestion 1: " + spokenQuestion + " ", i, j; for (i = 0; i < ANSWER_COUNT; i++) { - repromptText += (i+1).toString() + ". " + roundAnswers[i] + ". " + repromptText += "\n" + (i + 1).toString() + ". " + roundAnswers[i] + ". "; } speechOutput += repromptText; sessionAttributes = { @@ -467,7 +467,7 @@ function populateRoundAnswers(gameQuestionIndexes, correctAnswerIndex, correctAn var rand = Math.floor(Math.random() * (index - 1)) + 1; index -= 1; - var temp = answersCopy[index]; + temp = answersCopy[index]; answersCopy[index] = answersCopy[rand]; answersCopy[rand] = temp; } @@ -500,7 +500,7 @@ function handleAnswerRequest(intent, session, callback) { // If the user provided answer isn't a number > 0 and < ANSWER_COUNT, // return an error message to the user. Remember to guide the user into providing correct values. var reprompt = session.attributes.speechOutput; - var speechOutput = "Your answer must be a number between 1 and " + ANSWER_COUNT + ". " + reprompt; + speechOutput = "Your answer must be a number between 1 and " + ANSWER_COUNT + ". " + reprompt; callback(session.attributes, buildSpeechletResponse(CARD_TITLE, speechOutput, reprompt, false)); } else { @@ -517,14 +517,14 @@ function handleAnswerRequest(intent, session, callback) { speechOutputAnalysis = "correct. "; } else { if (!userGaveUp) { - speechOutputAnalysis = "wrong. " + speechOutputAnalysis = "wrong. "; } speechOutputAnalysis += "The correct answer is " + correctAnswerIndex + ": " + correctAnswerText + ". "; } // if currentQuestionIndex is 4, we've reached 5 questions (zero-indexed) and can exit the game session if (currentQuestionIndex == GAME_LENGTH - 1) { speechOutput = userGaveUp ? "" : "That answer is "; - speechOutput += speechOutputAnalysis + "You got " + currentScore.toString() + " out of " + speechOutput += speechOutputAnalysis + "\nYou got " + currentScore.toString() + " out of " + GAME_LENGTH.toString() + " questions correct. Thank you for playing!"; callback(session.attributes, buildSpeechletResponse(CARD_TITLE, speechOutput, "", true)); @@ -536,12 +536,12 @@ function handleAnswerRequest(intent, session, callback) { var roundAnswers = populateRoundAnswers(gameQuestions, currentQuestionIndex, correctAnswerIndex), questionIndexForSpeech = currentQuestionIndex + 1, - repromptText = "Question " + questionIndexForSpeech.toString() + ". " + spokenQuestion + " "; + repromptText = "\nQuestion " + questionIndexForSpeech.toString() + ": " + spokenQuestion + " "; for (var i = 0; i < ANSWER_COUNT; i++) { - repromptText += (i+1).toString() + ". " + roundAnswers[i] + ". " + repromptText += "\n" + (i + 1).toString() + ". " + roundAnswers[i] + ". "; } speechOutput += userGaveUp ? "" : "That answer is "; - speechOutput += speechOutputAnalysis + "Your score is " + currentScore.toString() + ". " + repromptText; + speechOutput += speechOutputAnalysis + "\nYour score is " + currentScore.toString() + ". " + repromptText; sessionAttributes = { "speechOutput": repromptText, @@ -596,9 +596,9 @@ function handleGetHelpRequest(intent, session, callback) { } function handleFinishSessionRequest(intent, session, callback) { - // End the session with a "Good bye!" if the user wants to quit the game + // End the session with a "Goodbye!" if the user wants to quit the game callback(session.attributes, - buildSpeechletResponseWithoutCard("Good bye!", "", true)); + buildSpeechletResponseWithoutCard("Goodbye!", "", true)); } function isAnswerSlotValid(intent) { @@ -654,4 +654,3 @@ function buildResponse(sessionAttributes, speechletResponse) { response: speechletResponse }; } -