Build a Quiz Game - Build a Quiz Game

Tell us what’s happening:

can someone give me solution? i already use AI but it doesnt work

Your code so far

const questions = [
  {
    category: "Food",
    question: "Apa bahan utama pembuatan keju?",
    choices: ["Susu", "Gandum", "Kedelai"],
    answer: "Susu"
  },
  {
    category: "Cooking",
    question: "Teknik memasak dengan uap air disebut?",
    choices: ["Menggoreng", "Mengukus", "Membakar"],
    answer: "Mengukus"
  },
  {
    category: "Nutrition",
    question: "Vitamin apa yang banyak terkandung dalam jeruk?",
    choices: ["Vitamin A", "Vitamin B", "Vitamin C"],
    answer: "Vitamin C"
  },
  {
    category: "Food",
    question: "Mana yang merupakan buah tropis?",
    choices: ["Apel", "Mangga", "Stroberi"],
    answer: "Mangga"
  },
  {
    category: "Cooking",
    question: "Alat yang digunakan untuk membalik masakan adalah?",
    choices: ["Sutil/Spatula", "Panci", "Cobek "],
    answer: "Sutil/Spatula"
  }
];


function getRandomQuestion(questionsArray) {
  const randomIndex = Math.floor(Math.random() * questionsArray.length);
  return questionsArray[randomIndex];
}

function getRandomComputerChoice(choicesArray) {
  const randomIndex = Math.floor(Math.random() * choicesArray.length);
  return choicesArray[randomIndex];
}

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



Your browser information:

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

Challenge Information:

Build a Quiz Game - Build a Quiz Game

You just need to call getResults and pass in the required arguments. You can then log the function call to see if the result returned in the console is what is expected. Your code looks good! :slight_smile:

I highly recommend avoiding LLMs when learning. You don’t yet know enough to know when the generated reply is correct, so you can end up wasting a huge amount of time due to a false response.

1 Like

yeah, i got confused, but challenge makes me gonna tryhard for result