Tell us what’s happening:
I don’t pass tests 8 and 9 but I dont get what i’m doing wrong.
and I pass test 13 but questionObj.answer gives undefined. How do I get the answer thas belongs to the question?
Your code so far
let questions=[
{
category:"color? ",
question:"what is your favorite color?",
choices:["blue","pink","green"],
answer:"green",
},
{
category:"living place?",
question:"Where do you live?",
choices:["Bursa","Ankara","Istanbul"],
answer:"Istanbul",
},
{
category:"job?",
question:"What is your job?",
choices:["computer-specialist","pro tennisplayer","teacher"],
answer:"computer-specialist",
},
{
category:"cooking?",
question:"What is your favorite food?",
choices:["Pizza","Egg","Rice"],
answer:"Pizza",
},
{
category:"sports?",
question:"What is your favorite sport?",
choices:["football", "volleyball","swimming"],
answer:"football",
}
];
let currentQuestionIndex = null;
function getRandomQuestion(){
currentQuestionIndex = Math.floor(Math.random() * questions.length);
return questions[currentQuestionIndex].question;
}
function getRandomComputerChoice() {
let choices = questions[currentQuestionIndex].choices;
let choiceIndex = Math.floor(Math.random() * choices.length);
return choices[choiceIndex];
}
let questionObj = getRandomQuestion()
console.log(questionObj)
let computerChoice = getRandomComputerChoice()
console.log(computerChoice)
function getResults(questionObj, computerChoice) {
if (computerChoice === questionObj.answer) {
return "The computer's choice is correct!";
} else {
return `The computer's choice is wrong. The correct answer is: ${questionObj.answer}`;
}
}
console.log(getResults(questionObj, computerChoice));
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36
Challenge Information:
Build a Quiz Game - Build a Quiz Game