Tell us what’s happening:
Hi, I am trying to run the code for the getResults() function to see what i get from it.
I have treid to write some code out to see if i get the correct return from the function, but am unsure of what to write.
let randomChoice = getRandomComputerChoice()
getResults(question[1], randomChoice)
Your code so far
const questions = [
{
category: "category1",
question: "question1?",
choices: ["choices11", "choices12", "answer1"],
answer: "answer1",
},
{
category: "category2",
question: "question2?",
choices: ["choices21", "choices22", "answer2"],
answer: "answer2",
},
{
category: "category3",
question: "question3?",
choices: ["choices31", "choices32", "answer3"],
answer: "answer3",
},
{
category: "category4",
question: "question4?",
choices: ["choices41", "choices42", "answer4"],
answer: "answer4",
},
{
category: "category5",
question: "question5?",
choices: ["choices51", "choices52", "answer5"],
answer: "answer5",
}
];
function getRandomQuestion (questions) {
let randomNum = Math.floor(Math.random() * questions.length);
return questions[randomNum];
}
function getRandomComputerChoice (choices) {
let randomChoice = Math.floor(Math.random() * choices.length);
return choices[randomChoice];
}
function getResults(questionObject, computerChoice) {
if(computerChoice === questionObject.answer) {
return "The computer's choice is correct!"
} else {
return `The computer's choice is wrong. The correct answer is: ${questionObject.answer}`
}
};
let randomChoice = getRandomComputerChoice()
getResults(question[1], randomChoice)
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