Подсчет ответов с правильным высказыванием - PullRequest
0 голосов
/ 05 июля 2019

Я создаю простой навык викторины для Алексы, но мне нужна помощь, чтобы заставить его работать правильно.

Я использую этот пример: https://github.com/alexa/skill-sample-nodejs-trivia/blob/en-US/lambda/custom/index.js

, который работает хорошо, но вот моя проблема:

function startGame(newGame, handlerInput) {
  const requestAttributes = handlerInput.attributesManager.getRequestAttributes();
  let speechOutput = newGame
    ? requestAttributes.t('NEW_GAME_MESSAGE', requestAttributes.t('GAME_NAME'))
      + requestAttributes.t('WELCOME_MESSAGE', GAME_LENGTH.toString())
    : '';
  const translatedQuestions = requestAttributes.t('QUESTIONS');
  const gameQuestions = populateGameQuestions(translatedQuestions);
  const correctAnswerIndex = Math.floor(Math.random() * (ANSWER_COUNT));

  const roundAnswers = populateRoundAnswers(
    gameQuestions,
    0,
    correctAnswerIndex,
    translatedQuestions
  );
  const currentQuestionIndex = 0;
  const spokenQuestion = Object.keys(translatedQuestions[gameQuestions[currentQuestionIndex]])[0];
  let repromptText = requestAttributes.t('TELL_QUESTION_MESSAGE', '1', spokenQuestion);
  for (let i = 0; i < ANSWER_COUNT; i += 1) {
    repromptText += `${i + 1}. ${roundAnswers[i]}. `;
  }

  speechOutput += repromptText;
  const sessionAttributes = {};

  const translatedQuestion = translatedQuestions[gameQuestions[currentQuestionIndex]];

  Object.assign(sessionAttributes, {
    speechOutput: repromptText,
    repromptText,
    currentQuestionIndex,
    correctAnswerIndex: correctAnswerIndex + 1,
    questions: gameQuestions,
    score: 0,
    correctAnswerText: translatedQuestion[Object.keys(translatedQuestion)[0]][0]
  });

Я изменил строки на:

const currentQuestionIndex = 0;
  const spokenQuestion = Object.keys(translatedQuestions[gameQuestions[currentQuestionIndex]])[0];
  let repromptText = requestAttributes.t('TELL_QUESTION_MESSAGE','1', spokenQuestion);
  for (let i=0; i < ANSWER_COUNT; i += 1) {
    repromptText += `${ANTWORT_ANTWORT} ${ANTWORT_TEXT[i]}: ${roundAnswers[i]}. `;
  }

, что хорошо работает, но только для первых вопросов, поэтому я хотел бы включить это для всех следующих вопросов.Я застрял с этим на 24 часа сейчас, и теперь прошу вас, парень, сделать мозговой удар

Спасибо

...