Build a Quiz Game - Build a Quiz Game

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

what are these comparisons for?

Sorry, I made a lot of changes, so there are a lot of errors in the last function, which I need to fix.

if you want to show how you would call the function, we can tell you if your understanding of the instructions is correct

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 arrayOfQuestions = [

questions[0].question,questions[1].question,questions[2].question,questions[3].question,questions[4].question,

];

const randomIndx = () => Math.floor(Math.random()*5);

const randomIndx2 = randomIndx();

function getRandomQuestion(arrayOfQuestions){

return arrayOfQuestions[randomIndx2]

}

//get a random answer within the choice’s question

let arrayOfAvailableChoices = questions[randomIndx2].choices;

const getRandomComputerChoice =(arrayOfAvailableChoices) =>

arrayOfAvailableChoices[Math.floor(Math.random()*3)]

;

const computerChoice = getRandomComputerChoice(arrayOfAvailableChoices);

// get the check result

function getResults(questionsObject, computerChoice) {

if (questionsObject.answer === computerChoice) {

return "Correct! The computer chose the right answer.";

} else {

return `Wrong! The correct answer was ${questionsObject.answer}.`;

}

}

const questionsObject = questions[randomIndx2];

console.log(getResults(questionsObject, computerChoice))

I’ve rewritten all the code and I’m still not getting past instructions 11 to 14.

The only problem I see is that I don’t understand the terms “Your function should take the question object as the first parameter and the computer’s choice as the second parameter.”

I’ve edited your post to improve the readability of the code. When you enter a code block into a forum post, please precede it with three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add the backticks.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

This seems to be implemented correctly. Try moving on to the next test.

I take note of this👌

Yes, the code was good but the return sentences was not exactly the same as in the statement.