Tell us what’s happening:
Ok. My code works in the console but i simply can’t get it to pass the tests from 11 and forward.
I believe I take the question as an object and the computer choice as a string in the getResults function.
Even though I can see that a lot of people have similar issues on this forum, I can’t use their posts as a solution on my problem.
Your code so far
const questions = [
{
category: "Hard Questions",
question: "What's the definition of the word codswallop?",
choices: ["Gibberish", "Nonsense", "Philosophy"],
answer: "Nonsense"
},
{
category: "Easy Questions",
question: "Which French emperor was attacked by a horde of rabbits?",
choices: ["Trump", "Bono", "Napoleon Bonaparte"],
answer: "Napoleon Bonaparte"
},
{
category: "Hard Questions",
question: "What Australian animal poops in cubes?",
choices: ["The Wombat", "Human Being", "Android"],
answer: "The Wombat"
},
{
category: "Hard Questions",
question: "After urinating on a bomb during WWII, Juliana, a Great Dane, was awarded what honor?",
choices: ["Nobel Peace Prize", "An Oscar", "The Blue Cross Medal"],
answer: "The Blue Cross Medal"
},
{
category: "Medium Questions",
question: "What is Bob Dylan's real last name?",
choices: ["Trump", "Zimmerman", "Bono"],
answer: "Zimmerman"
}
]
const getRandomQuestion = (questions) => {
let randomNum = Math.floor(Math.random() * questions.length);
let randomQuestion = questions[randomNum];
return randomQuestion;
}
const getRandomComputerChoice = (choices) => {
let randomNum = Math.floor(Math.random() * choices.length);
let randomChoice = choices[randomNum];
return randomChoice;
}
let quizResult = getRandomQuestion(questions);
let computerChoice = quizResult.choices;
let finalComputerChoice = getRandomComputerChoice(computerChoice);
let rightAnswer = quizResult.answer;
const getResults = (question, comAnswer) => {
if (question.answer === comAnswer) {
return "The computer's choice is correct"
} else return "The computer's choice is wrong. The correct answer is '" + quizResult.answer + "'";
}
console.log(quizResult.question + "\n");
console.log(`Computer answer: ${finalComputerChoice} \n`);
console.log(getResults(quizResult, finalComputerChoice));
console.log("\n")
console.log(`The type of quizResult is: ${typeof(quizResult)}`)
console.log(`The type of rightAnswer is: ${typeof(rightAnswer)}`)
console.log(`The type of computerChoice is: ${typeof(computerChoice)}`)
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36
Challenge Information:
Build a Quiz Game - Build a Quiz Game