Tell us what’s happening:
I am doing everything asked for but the test after no.8 is not working. What is going on?
Your code so far
const question1 = {
category: "History",
question: "Who was last president of USA?",
choices: ["Barack Obama", "Donald Trump", "Joe Biden"],
answer: "Joe Biden",
}
const question2 = {
category: "Me",
question: "What is my name?",
choices:[ "Hillary", "Obama", "something"],
answer: "Hillary",
}
const question3 = {
category: "Me",
question: "Where was I born?",
choices: ["USA", "China", "Mexico"],
answer: "USA",
}
const question4 = {
category: "Joe Biden",
question: "What is Joe Biden's nickname?",
choices: ["Joe", "Hoe", "Ore"],
answer: "Hoe",
}
const question5 = {
category: "Orange",
question: "Who is orange?",
choices: ["Donald Trump", "Orange fruit", "Orange Color"],
answer: "Donald Trump" ,
}
let questions = [question1, question2, question3, question4, question5];
let random;
function getRandomQuestion(array){
const max = array.length;
const min = 0;
random = Math.floor(Math.random() * (max - min) + min);
const randomQuestion = questions[random].question;
console.log(randomQuestion);
return randomQuestion;
}
getRandomQuestion(questions);
function getRandomComputerChoice(array){
const randomChoice = Math.floor(Math.random() * questions[random].choices.length);
const computerChoice = questions[random].choices[randomChoice];
console.log(computerChoice);
return computerChoice;
}
getRandomComputerChoice(questions);
function getResults(randomQuestion, computerChoice){
if (computerChoice == questions[random].answer){
console.log("The computer's choice is correct!");
return "The computer's choice is correct!";
} else {
console.log(`The computer's choice is wrong. The correct answer is: ${questions[random].answer}`)
return `The computer's choice is wrong. The correct answer is: ${questions[random].answer}`
}
}
getResults();
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36
Challenge Information:
Build a Quiz Game - Build a Quiz Game