From a7255119f30d52f6f62df619e41e51f0f6c70d09 Mon Sep 17 00:00:00 2001 From: Ayden Jahola Date: Fri, 6 Sep 2024 00:22:36 +0100 Subject: [PATCH] trivia: tldr, dont push into prod without testing --- commands/fun/trivia.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/commands/fun/trivia.js b/commands/fun/trivia.js index dfcaea7..7864186 100644 --- a/commands/fun/trivia.js +++ b/commands/fun/trivia.js @@ -94,6 +94,9 @@ module.exports = { const incorrectAnswers = triviaQuestion.incorrect_answers.map(decode); let allAnswers = [...incorrectAnswers, correctAnswer]; + // Declare answerMap before any conditions + let answerMap = {}; + // Handle True/False questions specifically if (triviaQuestion.type === "boolean") { // Always keep "True" as option 1 and "False" as option 2 @@ -102,21 +105,13 @@ module.exports = { // Shuffle answers for other types of questions allAnswers = allAnswers.sort(() => Math.random() - 0.5); - // Create a mapping of numbers to answers + // Assign the map without redeclaring answerMap = allAnswers.reduce((map, answer, index) => { map[index + 1] = answer; return map; }, {}); } - allAnswers = allAnswers.sort(() => Math.random() - 0.5); // Shuffle answers - - // Create a mapping of numbers to answers - const answerMap = allAnswers.reduce((map, answer, index) => { - map[index + 1] = answer; - return map; - }, {}); - // Create an embed with the trivia question and numbered options const triviaEmbed = new EmbedBuilder() .setColor("#0099ff")