Tell us what’s happening:
Hello Coders,
I am having a problem related to the Build a Quiz Game in the getResults part. The result itself matches the requirements, but i cannot pass this step in the test. I have tried many ways how to solve it, but seems that i cannot find the bug. I do not understand if it is related to a mismatching of the results data types or there is a problem in the getRandomComputerChoice or or or. Any help is appreciated.
Your code so far
const questions = [
{
category: "Programming",
question: "Which of the following is a compiled programming language?",
choices: ["Phyton", "Java", "HTML"],
answer: "Java"
},
{
category: "Programming",
question: "Which keyword is used to define a function in JavaScript?",
choices: ["func", "function", "dev"],
answer: "function"
},
{
category: "Computer",
question: "In binary, what is the value of 1011 in decimal?",
choices: ["11", "13", "15"],
answer: "11"
},
{
category: "Computer",
question: "Which part of the computer is considered the “brain”?",
choices: ["hard-drive", "CPU", "RAM"],
answer: "CPU"
},
{
category: "Computer",
question: "What does the acronym “HTTP” stand for?",
choices: ["HyperText Transfer Protocol", "High Transmission Text Program", "Hyperlink Transfer Process"],
answer: "HyperText Transfer Protocol"
},
];
const getRandomQuestion = (questions) => {
let randomQ = Math.floor(Math.random() * questions.length);
return questions[randomQ];
}
const question = getRandomQuestion(questions);
const getRandomComputerChoice = (choices) => {
let randomN = Math.floor(Math.random() * choices.length);
return choices[randomN];
};
const choice = getRandomComputerChoice(question.choices);
const getResults = (question, choice) => {
if(choice === question.answer){
return `The computer's choice is correct!`;
} else {
return `The computer's choice is wrong. The correct answer is: ${question.answer}.`;
};
}
console.log(question);
console.log(choice);
console.log(getResults(question, choice));
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36
Challenge Information:
Build a Quiz Game - Build a Quiz Game
https://www.freecodecamp.org/learn/full-stack-developer/lab-quiz-game/lab-quiz-game