Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

reindeerGames fixes #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions samples/reindeerGames/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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));
Expand All @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -654,4 +654,3 @@ function buildResponse(sessionAttributes, speechletResponse) {
response: speechletResponse
};
}