Build a Quiz Game - Build a Quiz Game

Tell us what’s happening:

I am doing everything asked for but the test after no.8 is not working. What is going on?

Your code so far

const question1 = {
  category: "History",
  question: "Who was last president of USA?",
  choices: ["Barack Obama", "Donald Trump", "Joe Biden"],
  answer: "Joe Biden",
}
const question2 = {
  category: "Me",
  question: "What is my name?",
  choices:[ "Hillary", "Obama", "something"],
  answer: "Hillary",
}
const question3 = {
  category: "Me",
  question: "Where was I born?",
  choices: ["USA", "China", "Mexico"],
  answer: "USA",
}
const question4 = {
  category: "Joe Biden",
  question: "What is Joe Biden's nickname?",
  choices: ["Joe", "Hoe", "Ore"],
  answer: "Hoe",
}
const question5 = {
  category: "Orange",
  question: "Who is orange?",
  choices: ["Donald Trump", "Orange fruit", "Orange Color"],
  answer: "Donald Trump" ,
}
let questions = [question1, question2, question3, question4, question5];

let random;

function getRandomQuestion(array){
  const max = array.length;
  const min = 0;
  random = Math.floor(Math.random() * (max - min) + min);
  const randomQuestion = questions[random].question;
  console.log(randomQuestion);
  return randomQuestion;
}
getRandomQuestion(questions);

function getRandomComputerChoice(array){
    const randomChoice = Math.floor(Math.random() * questions[random].choices.length);
    const computerChoice = questions[random].choices[randomChoice];
    console.log(computerChoice);
    return computerChoice;

}
getRandomComputerChoice(questions);

function getResults(randomQuestion, computerChoice){
  if (computerChoice == questions[random].answer){
    console.log("The computer's choice is correct!");
    return "The computer's choice is correct!";
  } else {
    console.log(`The computer's choice is wrong. The correct answer is: ${questions[random].answer}`)
    return `The computer's choice is wrong. The correct answer is: ${questions[random].answer}`
  }
}
getResults();




Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36

Challenge Information:

Build a Quiz Game - Build a Quiz Game

please read again the requirments, what kind of array is given to getRandomComputerChoice? it’s not the array of questions

also you need to check again the requirements for what is passed to getResults

function getRandomComputerChoice(choices)

you means something like this?

I mean you need to read the requirements. The name of the parameter does not matter, it can be banana if that’s what you want, the issue is what you do with the parameter. So make sure to read the requirements about what the value of the parameter will be

Tell us what’s happening:

I don’t understand what to do. I can’t think of anything after this for test 11 and more. Please help.

Your code so far

const question1 = {
  category: "History",
  question: "Who was last president of USA?",
  choices: ["Barack Obama", "Donald Trump", "Joe Biden"],
  answer: "Joe Biden",
}
const question2 = {
  category: "Me",
  question: "What is my name?",
  choices:[ "Hillary", "Obama", "something"],
  answer: "Hillary",
}
const question3 = {
  category: "Me",
  question: "Where was I born?",
  choices: ["USA", "China", "Mexico"],
  answer: "USA",
}
const question4 = {
  category: "Joe Biden",
  question: "What is Joe Biden's nickname?",
  choices: ["Joe", "Hoe", "Ore"],
  answer: "Hoe",
}
const question5 = {
  category: "Orange",
  question: "Who is orange?",
  choices: ["Donald Trump", "Orange fruit", "Orange Color"],
  answer: "Donald Trump" ,
}
let questions = [question1, question2, question3, question4, question5];

let random;

function getRandomQuestion(array){
  random = Math.floor(Math.random()*array.length);
  return array[random];
}
getRandomQuestion(questions);

function getRandomComputerChoice(array){
  return array[random];
}

function getResults(questions, computerChoice){
  if (computerChoice == questions[random]?.answer){
    console.log("The computer's choice is correct!");
  } else {
    console.log(`The computer's choice is wrong. The correct answer is: ${questions[random].answer}`);
    return  `The computer's choice is wrong. The correct answer is: ${questions[random].answer}`;
  }
}


console.log(questions[random].answer)



Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36

Challenge Information:

Build a Quiz Game - Build a Quiz Game

What is test 11?

Which specific lines do you think should satisfy test 11?

It is related to getResult function and I don’t know what the hell I am supposed to do there.

Can you please try clearly and fully answering both questions?

These lines should satisfy test 11 and “Your getResults function should take the question object as the first parameter and the computer’s choice as the second parameter.” This is test 11

Do you take a question object though? Or an array of question objects?

I have merged your two topics for this challenge, please do not create multiple topics for the same challenge

I have no idea man. What the hell is going on?

If you do not know if you are using an array or object, I would go back and review both.

I know I am using an array.

But how do I put object in that?

what do the requirements say about what the getResults function take as argument?

double check your assumption against the lab description

let objQuestion = new Object(questions[random]);

let computerChoice = getRandomComputerChoice(objQuestion);




function getResults(objQuestion, computerChoice){

  if (computerChoice == objQuestion.answer){

    console.log("The computer's choice is correct!");

    return "The computer's choice is correct!";

  } else {

    console.log(`The computer's choice is wrong. The correct answer is: ${objQuestion.answer}`);

    return  `The computer's choice is wrong. The correct answer is: ${objQuestion.answer}`;

  }

}

You mean something like this?

What is this line for?

To turn the question into an object.

Did the instructions ask you to do that?

It’s working right now. So, I am not touching it.

Now I have a problem with test 9.