Tell us what’s happening:
My code seems to be functioning properly when I log to the console. However, if I run the test multiple times, it gives me different failures each time. I am not sure what the precise problem is, but 13 seems to be failing most frequently. 1 and 2 has also failed a few times, which was strange.
Your code so far
const questions = [
{
category: 'Mathematics',
question: 'What is 2 x 7?',
choices:['a: 21', 'b: 42', 'c:14'],
answer: 'c:14'
},
{
category:'English',
question:'What is the antonym of hot?',
choices: ['warm', 'spicy', 'cold'],
answer: 'cold'
},
{
category: 'Science',
question:'How many bones are in the adult human body?',
choices: ['270', '206', '109'],
answer: '206'
},
{
category: 'Programming',
question:'Which one of the following is a programming language?',
choices:['Javascript', 'Pythos', 'Mocha'],
answer: 'Javascript'
},
{
category: 'History',
question:'In which year did World War 2 end?',
choices: ['1900', '1976', '1945'],
answer: '1945'
}];
let index = Math.round(Math.random() * questions.length);
let choiceIndex = Math.round(Math.random());
function getRandomQuestion(array){
let randomQuestionObject = array[index];
return randomQuestionObject;
}
let randomObject = getRandomQuestion(questions);
let choices = randomObject.choices;
function getRandomComputerChoice(choices){
let computerChoice = choices[choiceIndex];
return computerChoice;
}
let computerChoice = getRandomComputerChoice(choices);
function getResults(randomObject, computerChoice){
if (computerChoice === randomObject.answer){
return `The computer's choice is correct!`;
} else if (computerChoice !== randomObject.answer){
return `The computer's choice is wrong. The correct answer is: ${randomObject.answer}.`;
}
}
getResults(randomObject, computerChoice);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Challenge Information:
Build a Quiz Game - Build a Quiz Game