Tell us what’s happening:
“Your getResults function must take the question object as the first parameter and the computer choice as the second parameter.” Isn’t that what I did? My question is, what does the instruction mean? I’ll correct instructions 12, 13, and 14 after I’ve completed 11.
Your code so far
const 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",
}
];
//get a random question
const arrayQuestions = [
questions[0].question,
questions[1].question,
questions[2].question,
questions[3].question,
questions[4].question
];
const getRandomQuestion = (arrayQuestions) =>
arrayQuestions[Math.floor(Math.random()*5)] ;
let randomQuest = getRandomQuestion(arrayQuestions);
//get a random computer choice
const allChoiceArrays = [
questions[0].choices,
questions[1].choices,
questions[2].choices,
questions[3].choices,
questions[4].choices
];
const getRandomComputerChoice = (allChoiceArrays) => {
// Randomly select one of the arrays of choices
const randomChoiceArray = allChoiceArrays[Math.floor(Math.random() * allChoiceArrays.length)];
// Randomly select a choice from the chosen array
return randomChoiceArray[Math.floor(Math.random() * randomChoiceArray.length)];
};
let computerChoice = getRandomComputerChoice(allChoiceArrays);
console.log(computerChoice);
//get a random result
function getResults(randomQuest, computerChoice ){
if ((randomQuest === questionsArray[0] && computerChoice === choicesArray[0])||(randomQuest === questionsArray[1] && computerChoice === choicesArray[1])||(randomQuest === questionsArray[2] && computerChoice === choicesArray[2])||(randomQuest === questionsArray[3] && computerChoice === choicesArray[3])||(randomQuest === questionsArray[4] && computerChoice === choicesArray[4])){
return "The computer's choice is correct!";
} else {
return `The computer's choice is wrong. The correct answer is: <correct-answer>`; //the else return is not finished correctly!
}
};
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36
Challenge Information:
Build a Quiz Game - Build a Quiz Game
