Hello.
I am working on this task : Build a Quiz Game
My code does not pass tests 11, 12 and 13.
I made some tests and it works fine though.
Could you please provide some tips to solve the issue. Thanks.
const questions = [];
const topic1 = {
category: 'Sport',
question: 'Who won the 2023 French Open?',
choices: ['Carlos Alcaraz', 'Novak Djokovic', 'Rafael Nadal'],
answer: 'Novak Djokovic',
};
const topic2 = {
category: 'Politics',
question: 'Who is the current president of the USA?',
choices: ['Joe Biden', 'Donald Trump', 'Kamala Harris'],
answer: 'Donald Trump',
};
const topic3 = {
category: 'Economy',
question: 'What does GDP stand for?',
choices: ['Great Development Programme', 'Grand Definition of Performance', 'Gross Domestic Product'],
answer: 'Gross Domestic Product',
};
const topic4 = {
category: 'Geography',
question: 'What country is the most inhabited on Earth?',
choices: ['India', 'China', 'Indonesia'],
answer: 'India',
};
const topic5 = {
category: 'Cinema',
question: 'Who directed the movie \"The Wolf of Wall Street\"?',
choices: ['Leonardo Di Caprio', 'Quentin Tarantino', 'Martin Scorsese'],
answer: 'Martin Scorsese',
};
questions.push(topic1, topic2, topic3, topic4, topic5);
const questionList =[];
questionList.push(topic1.question, topic2.question, topic3.question, topic4.question, topic5.question);
function getRandomQuestion(array) {
const randomIndex = Math.floor(Math.random() * array.length);
return array[randomIndex];
}
function getRandomComputerChoice(array) {
const randomIndex = Math.floor(Math.random() * array.length);
return array[randomIndex];
}
const getResults = (question, guess) => {
const answer = questions[questionList.indexOf(question)].answer;
if (guess === answer) {
return "The computer's choice is correct!";
} else {
return `The computer's choice is wrong. The correct answer is: ${answer}`;
}
}
const randomQuestion = getRandomQuestion(questionList)
console.log(randomQuestion);
const randomChoice = getRandomComputerChoice(questions[questionList.indexOf(randomQuestion)].choices);
console.log(randomChoice);
const result = getResults(randomQuestion, randomChoice);
console.log(result);