Tell us what’s happening:
if the questions array and choices array had the same length my program were true, but it is not what should i do?
Your code so far
let questions=[
{
category:"color? ",
question:"what is your favorite color?",
choices:["blue","pink","green"],
answer:"green",
},
{
category:"living place?",
question:"do you like living there ?",
choices:["Bursa","Ankara","Istanbul"],
answer:"Istanbul",
},
{
category:"field of study?",
question:"do you grageuated?",
choices:["computer","Math","teacher"],
answer:"computer",
},
{
category:"cooking?",
question:"What is your favorite food?",
choices:["Pizza","Ege","Rice"],
answer:"Ege",
},
{
category:"sports?",
question:"What is your favorite sport?",
choices:["football", "volleyball","swimming"],
answer:"volleyball",
}
];
let random = Math.floor(Math.random() * questions.length);
function getRandomQuestion(questions) {
let randomQuestion = random;
return questions[randomQuestion].question;
};
//FUNCTION CALL
let gRandomQuestion = getRandomQuestion(questions);
let finduserAnswer = questions.find(user => user.question === gRandomQuestion);
let userAnswer = finduserAnswer.answer;
function getRandomComputerChoice(choices) {
return choices[random];
};
//FUNCTION CALL
let computerChoice = getRandomComputerChoice(questions[random].choices);
//result Function
function getResults() {
if (computerChoice == userAnswer) {
return "The computer's choice is correct!";
}
else {
return `The computer's choice is wrong. The correct answer is: ${userAnswer}.}`;
}
};
console.log(getResults());
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Challenge Information:
Build a Quiz Game - Build a Quiz Game