Skip to content
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
46 changes: 23 additions & 23 deletions lambda/custom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ function populateRoundAnswers(
}

function isAnswerSlotValid(intent) {
const answerSlotFilled = intent
&& intent.slots
&& intent.slots.Answer
&& intent.slots.Answer.value;
const answerSlotIsInt = answerSlotFilled
&& !Number.isNaN(parseInt(intent.slots.Answer.value, 10));
return answerSlotIsInt
&& parseInt(intent.slots.Answer.value, 10) < (ANSWER_COUNT + 1)
&& parseInt(intent.slots.Answer.value, 10) > 0;
const answerSlotFilled = intent
&& intent.slots
&& intent.slots.item
&& intent.slots.item.value;
const answerSlotIsInt = answerSlotFilled
&& !Number.isNaN(parseInt(intent.slots.item.value, 10));
return answerSlotIsInt
&& parseInt(intent.slots.item.value, 10) < (ANSWER_COUNT + 1)
&& parseInt(intent.slots.item.value, 10) > 0;
}

function handleUserGuess(userGaveUp, handlerInput) {
Expand All @@ -99,22 +99,22 @@ function handleUserGuess(userGaveUp, handlerInput) {
const translatedQuestions = requestAttributes.t('QUESTIONS');


if (answerSlotValid
&& parseInt(intent.slots.Answer.value, 10) === sessionAttributes.correctAnswerIndex) {
currentScore += 1;
speechOutputAnalysis = requestAttributes.t('ANSWER_CORRECT_MESSAGE');
} else {
if (!userGaveUp) {
speechOutputAnalysis = requestAttributes.t('ANSWER_WRONG_MESSAGE');
if (answerSlotValid
&& parseInt(intent.slots.item.value, 10) === sessionAttributes.correctAnswerIndex) {
currentScore += 1;
speechOutputAnalysis = requestAttributes.t('ANSWER_CORRECT_MESSAGE');
} else {
if (!userGaveUp) {
speechOutputAnalysis = requestAttributes.t('ANSWER_WRONG_MESSAGE');
}

speechOutputAnalysis += requestAttributes.t(
'CORRECT_ANSWER_MESSAGE',
correctAnswerIndex,
correctAnswerText
);
}

speechOutputAnalysis += requestAttributes.t(
'CORRECT_ANSWER_MESSAGE',
correctAnswerIndex,
correctAnswerText
);
}

// Check if we can exit the game session after GAME_LENGTH questions (zero-indexed)
if (sessionAttributes.currentQuestionIndex === GAME_LENGTH - 1) {
speechOutput = userGaveUp ? '' : requestAttributes.t('ANSWER_IS_MESSAGE');
Expand Down