Tell us what’s happening:
The last part for getResults isn’t passing. Everything is working as it should,d though with the correct checks.
Your code so far
const questions =
[
//object1
{
category: "Food",
question: "What is my favorite type of food?",
choices: ["Indian","Chinese","Greek"],
answer: "Indian"
},
//object2
{
category: "Pets",
question: "What is my type of Pet?",
choices: ["Cat","Dog","Fish"],
answer: "Cat"
},
//object3
{
category: "Weather",
question: "What is my favorite type of Weather?",
choices: ["Snow","Rain","Sun"],
answer: "Rain"
},
//object4
{
category: "Colors",
question: "What is my favority color?",
choices: ["Black","White","Blue"],
answer: "White"
},
//object5
{
category: "Music Instruments",
question: "What is my favorite Instrument?",
choices: ["Piano","Guitar","Trumpet"],
answer: "Guitar"
}
];
function getRandomQuestion(array){
const min = 0;
const max = 4;
const randomObject = Math.round(Math.random() * (max - min) + min);
return array[randomObject];
}
function getRandomComputerChoice(array){
const min = 0;
const max = array.length-1
const randomAnswer = Math.round(Math.random() * (max - min) + min);
const randomSelectedAnswer = array[randomAnswer]
return randomSelectedAnswer
}
const selectedObject = getRandomQuestion(questions)
const selectedChoices = selectedObject.choices
const answer = selectedObject.answer
const computerSelectedAnswer = getRandomComputerChoice(selectedChoices)
getResults(answer, computerSelectedAnswer)
function getResults(selectedObject, computerSelectedAnswer){
if(computerSelectedAnswer === selectedObject){
return console.log("The computer's choice is correct!");
}else if(computerSelectedAnswer !== selectedObject){
return console.log(`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/145.0.0.0 Safari/537.36
Challenge Information:
Build a Quiz Game - Build a Quiz Game
sanity
February 13, 2026, 5:49am
2
Hmm, this suggests, the getResults after all is not returning what it should. How could be confirmed what it returns?
1 Like
ILM
February 13, 2026, 8:43am
3
what is selectedObject? is it an object? can that be the same as a string?
1 Like
const selectedObject = getRandomQuestion(questions)
getResults()
function getResults(answer, computerAnswer){
const selectedChoices = selectedObject.choices
answer = selectedObject.answer
console.log(answer)
computerAnswer = getRandomComputerChoice(selectedChoices)
console.log(computerAnswer)
if(computerAnswer === answer){
return console.log(“The computer’s choice is correct!”);
}else if(computerAnswer !== answer){
return console.log(The computer's choice is wrong. The correct answer is: ${answer})
}
}
I used console logs to show the output which seems like it is outputting the correct stuff like when they are the same it says correct and when they are not it gives the right answer
ILM
February 13, 2026, 5:33pm
5
why are you dong this? you already have answer as function parameter
random1234:
getResults()
if you want to test getResults call it with what the user stories say it’s going to receive:
You should have a function named getResults that takes the question object as the first parameter and the computer’s choice as the second parameter.
if you call it with no arguments your testing is useless
1 Like
Ok I gotcha think i got a little lost along the way. So I am going to take 2 inputs values one that is the question object (random question object) and then one that is the answer of that question object ?
ILM
February 13, 2026, 5:59pm
7
one is a question object, like what you get from getRandomQuestion and the other is the option to check, like what you get from getRandomComputerChoice
1 Like
Ok, this is what I have so far this time it is taking in 2 inputs and then inside the function is it computing the computerChoice to use for checking against answer
//Testing the input
const questionObject = getRandomQuestion(questions)
const answer = questionObject.answer
getResults(questionObject, answer)
function getResults(questionObject, answer){
//computing the computers choice from quesitonObject
const computerAnswer = getRandomComputerChoice(questionObject.choices)
//results to check in if statements
console.log("Computer answer: " + computerAnswer)
console.log("questionObject answer: " + answer)
if(computerAnswer === answer){
return console.log(“The computer’s choice is correct!”);
}else if(computerAnswer !== answer){
return console.log(The computer's choice is wrong. The correct answer is: ${answer})
}
}
still isn’t passing
ILM
February 13, 2026, 6:25pm
9
why are you doing this inside the function? the answer to test is already your function parameter
1 Like
Oh ok I just saw that computerChoice is the second parameter. Thank you for the help by the way!!! Ok, so here is the current
//Testing the input
const questionObject = getRandomQuestion(questions)
//computing the computers choice from quesitonObject
const computerAnswer = getRandomComputerChoice(questionObject.choices)
getResults(questionObject, computerAnswer)
function getResults(questionObject, computerAnswer){
const answer = questionObject.answer
//results to check in if statements
console.log("Computer answer: " + computerAnswer)
console.log("questionObject answer: " + answer)
if(computerAnswer === answer){
return console.log(“The computer’s choice is correct!”);
}else if(computerAnswer !== answer){
return console.log(The computer's choice is wrong. The correct answer is: ${answer})
}
}
ILM
February 13, 2026, 6:48pm
11
random1234:
return console.log(
what are you asked to do with those two final strings? return them or log them?
1 Like
Woohoo!!! It said to return them, not console.log! made it easier for troubleshooting, though :0 Thanks for the help ILM
ILM
February 13, 2026, 7:08pm
13
console.log is really useful! use it a lot! just don’t put it in front of return, because the effect on the function output of return console.log() is equal to return undefined
1 Like