Tell us what’s happening:
Program performs exactly as described but fails tests 8, 9, 11, 12, and 13. I have tried multiple ways, but this is the only way that works correctly everytime. Whatis Wrong?!?!?!
Your code so far
const questions = [
{ category: "Music",
question: "Who was the Beatles first drummer?",
choices: ["Ringo Starr", "Pete Best", "Robert Starkey"],
answer: "Pete Best" },
{ category: "Music",
question: "What was Motley Crue's original name?",
choices: ["Dark Blue", "New Years", "Xmas"],
answer: "Xmas" },
{ category: "Movies",
question: "In what city does Hogwart's reside?",
choices: ["London", "Switzerland", "Romania"],
answer: "London" },
{ category: "Movies",
question: "What sport, is the movie 'Draft Day' about?",
choices: ["Basketball", "Baseball", "Football"], answer: "Football" },
{ category: "Music", question: "Who wrote and performed the soundtrack for the movie 'Flash Gordon'?", choices: ["Kiss", "Led Zeppelin", "Queen"], answer: "Queen" },];
let randomQuestion;
let randomAnswer;
function getRandomQuestion(array) {
randomQuestion = Math.floor(Math.random()*questions.length);
//console.log(randomQuestion);
return array[randomQuestion].question;
}
console.log(getRandomQuestion(questions));
function getRandomComputerChoice(answerArr) {
randomAnswer = Math.floor(Math.random()*questions[randomQuestion].choices.length);
//console.log(randomAnswer);
return answerArr.choices[randomAnswer];
}
console.log(getRandomComputerChoice(questions[randomQuestion]));
function getResults(quest, compAnswer) {
if(quest === compAnswer) {
console.log("The computer's choice is correct!");
return "The computer's choice is correct!";
} else {
return `The computer's choice is wrong. The correct answer is: ${questions[randomQuestion].answer}`
}
}
console.log(getResults(questions[randomQuestion].answer, questions[randomQuestion].choices[randomAnswer]));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
Challenge Information:
Build a Quiz Game - Build a Quiz Game
https://www.freecodecamp.org/learn/full-stack-developer/lab-quiz-game/lab-quiz-game
