Tell us what’s happening:
Hello, I need some help with this task. My code seems to work but still seemingly doesn’t meet the requirements on step 8, 10, 11 and 12.
It’s been three days that i am trying to pass this step.
Can someone tell me what’s wrong in my declared functions. I have added some comments to follow the logic in my code.
Thanks in advance
Your code so far
const questions = [
{category: "sports", question: "Who won football world cup in 1998?", choices: ["France", "Italy", "Bresil"], answer: "France"},
{category: "politics", question: "Who won 2024 US presidentials?", choices: ["Trump", "Biden", "Camilla"], answer: "Trump"},
{category: "food", question: "What is the national dish in Algeria?", choices: ["Couscous", "Chorba", "Sfiti"], answer: "Couscous"},
{category: "Foreign languages", question: "How to say blue in Spanish?", choices: ["Azul", "Rojo", "Amarillo"], answer: "Azul"},
{category: "Geography", question: "What is the capital of Spain?", choices: ["Malaga", "Barcelona", "Madrid"], answer: "Madrid"}
];
// Bellow is a function that returns a random question Object
const getRandomQuestion = function(questions) {
const randomIndex = Math.floor(Math.random() * questions.length);
return questions[randomIndex];
}
let question_Obj = getRandomQuestion(questions)
// Bellow is a function to get a random computer choice
const getRandomComputerChoice = function(getRandomQuestion){
const randomIndex = Math.floor(Math.random() * getRandomQuestion.choices.length);
return getRandomQuestion.choices[randomIndex]
}
// Bellow is stored the outcome of the getRandomComputerChoice() in a variable
getRandomComputerChoice(question_Obj)
let computerChoice = getRandomComputerChoice(question_Obj)
// Below is a function that evaluates the computer's returned choice and returns the necessay feedback
function getResults(computerChoice, question_Obj){
if (computerChoice === question_Obj.answer) {
return "The computer's choice is correct!"
} else {
return `|The computer's choice is wrong. The correct answer is: ${question_Obj.answer}`
}
};
getResults(computerChoice, question_Obj);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Challenge Information:
Build a Quiz Game - Build a Quiz Game