Build a Quiz Game - Build a Quiz Game

Tell us what’s happening:

The code is not executing Properly, as my code is correct but it is not accepting it somehow. Thankyou

Your code so far

const questions = [
  {
    category: "Science",
    question: "What is the chemical symbol for water?",
    choices: ["H2O", "CO2", "NaCl"],
    answer: "H2O"
  },
  {
    category: "History",
    question: "In what year did World War II begin?",
    choices: ["1939", "1914",  "1929"],
    answer: "1939"
  },
  {
    category: "Geography",
    question: "What is the capital of France?",
    choices: [ "Berlin", "Madrid", "Paris"],
    answer: "Paris"
  },
  {
    category: "Mathematics",
    question: "What is the value of pi (π) approximately equal to?",
    choices: ["3.14", "2.71", "4.20"],
    answer: "3.14"
  },
  {
    category: "Literature",
    question: "Who wrote the play 'Hamlet'?",
    choices: ["Charles Dickens","William Shakespeare", "Mark Twain"],
    answer: "William Shakespeare"
  },
  {
    category: "Technology",
    question: "What does CPU stand for?",
    choices: ["Central Processing Unit", "Computer Peripheral Unit", "Control Processing Unit"],
    answer: "Central Processing Unit"
  },
  {
    category: "Sports",
    question: "How many players are there in a basketball team on the court at one time?",
    choices: ["5", "6", "4"],
    answer: "5"
  },
  {
    category: "Music",
    question: "Who was known as the 'King of Rock and Roll'?",
    choices: ["Michael Jackson", "Elvis Presley", "Jimi Hendrix"],
    answer: "Elvis Presley"
  }
];


function getRandomComputerChoice(arr){
  let random = Math.floor(Math.random() * arr.length);
  return arr[random];
}

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

let randoQues = getRandomQuestion(questions);
let choise = getRandomComputerChoice(randoQues.choices);

function getResults(randoQues, choise){
  if(randoQues.answer == choise){
    return "The computer's choice is correct!";
  }else{
    return `The computer's choice is wrong. The correct answer is: ${randoQues.answer}`
  }
}

Your browser information:

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

Challenge Information:

Build a Quiz Game - Build a Quiz Game

Welcome to the forum @ansh

  1. You should have a function named getRandomQuestion that returns a random question object from the questions array.

Your code is passing a parameter to the function. The instructions did not ask for one.

Happy coding

Edit: The instructions doesn’t asked a parameter for the getRandomQuestion function.