Tell us what’s happening:
I’ve tried everything I can think of, switched the variables around 100 times and I just can’t see where I’m going wrong. Please give me some guidance on this. Thanks
Your code so far
const questions = [
{
category: "desserts",
question: "Favorite dessert?",
choices: ['Ice Cream', 'Cake', 'Brownies'],
answer: 'Brownies'
},
{
category: "cars",
question: "Favorite car?",
choices: ['Tesla', 'Mercedes', 'Infiniti'],
answer: 'Mercedes'
},
{
category: "socials",
question: "Favorite social media?",
choices: ['Facebook', 'Instagram', 'X'],
answer: 'Facebook'
},
{
category: "veggies",
question: "Favorite vegetable?",
choices: ['Asparagus', 'Broccolli', 'Potatoes'],
answer: 'Asparagus'
},
{
category: "codeLangs",
question: "Favorite Coding Language?",
choices: ['Python', 'JavaScript', 'C++'],
answer: 'Python'
}
]
const getRandomQuestion = (questions) =>{
let randomQuestion = Math.floor(Math.random() * 5);
return questions[randomQuestion];
}
const getRandomComputerChoice = (choices) => {
let randomChoice = Math.floor(Math.random() * 3);
return choices[randomChoice];
}
const getResults = (randomQuestion, randomChoice) => {
if (randomQuestion === randomChoice) { return "The computer's choice is correct!"}
else {
return `"The computer's choice is wrong. The correct answer is: ${answer}"`;
}
}
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
ILM
November 9, 2025, 5:20pm
2
let’s look at getResults, if the first parameter is one of the objects in the array, and the second parameter a string, how do you check is the answer in the object?
1 Like
jfo0707
November 10, 2025, 6:05pm
3
Thanks for the feedback. I’ve decided to reset the lesson and start over.
That’s a shame. Your code looked good except for not understanding how to access the answer property in your array of question objects.
jfo0707
November 10, 2025, 8:29pm
5
Tell us what’s happening:
I can’t figure out why just changing the operator in step 13 makes steps 11 and 12 pass, but not 13. If I use the < operator, 11 and 12 pass. But not if I use the !== operator. I’m making a mess here. Please give me advice.
Your code so far
const questions = [
{
category: "desserts",
question: "Favorite dessert?",
choices: ['Ice Cream', 'Cake', 'Brownies'],
answer: 'Brownies'
},
{
category: "cars",
question: "Favorite car?",
choices: ['Tesla', 'Mercedes', 'Infiniti'],
answer: 'Mercedes'
},
{
category: "socials",
question: "Favorite social media?",
choices: ['Facebook', 'Instagram', 'X'],
answer: 'Facebook'
},
{
category: "veggies",
question: "Favorite vegetable?",
choices: ['Asparagus', 'Broccolli', 'Potatoes'],
answer: 'Asparagus'
},
{
category: "codeLangs",
question: "Favorite Coding Language?",
choices: ['Python', 'JavaScript', 'C++'],
answer: 'Python'
}
]
function getRandomQuestion(questions) {
let randomQuestion = Math.floor(Math.random() * questions.length);
return questions[randomQuestion];
}
function getRandomComputerChoice(choices) {
let randomComputerChoice = Math.floor(Math.random() * choices.length);
return choices[randomComputerChoice];
}
function getResults(randomQuestion, randomComputerChoice) {
if (randomComputerChoice === randomQuestion.answer)
return "The computer's choice is correct!";
else if (randomQuestion.answer < randomComputerChoice) {
return `The computer's choice is wrong. The correct answer is: ${answer}`
}
}
console.log(questions);
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
sanity
November 10, 2025, 9:31pm
6
Have you tried to play around a bit with the functions to see what is returned? For example you can add at the bottom of the code:
const question = getRandomQuestion(questions);
const computerChoice = getRandomComputerChoice(question.choices);
console.log(getResults(question, computerChoice))
jfo0707
November 10, 2025, 10:11pm
7
I’ve been trying something like that by defining some global variables. I’ll keep trying with your idea in mind. Thank you.
Why did you add this if condition? I mean, if the answer does not satisfy your if condition, wouldn’t it then be the wrong answer?
Also, where have you declared an answer variable in this code? Is there something else you could use here that you have already used?
jfo0707
November 11, 2025, 12:37am
9
I was just experimenting to see what effect it would have. It confused me even more.
ILM
November 11, 2025, 10:13am
10
I have merged your two topics, do not create multiple topics for the same challenge
1 Like