Tell us what’s happening:
keeps saying // running tests
4. The question key should have the value of a string representing a question.
// tests completed
Your code so far
const questions = [
{
category:"auto",
question:"slowest?", // This is a string
choices:["bmw","audi","benz"],
answer: "benz"
},
{
category:"book",
question:"dumbest?",
choices:["harry potter","dr sues","diary"],
answer: "harry potter"
},
{
category:"js",
question:"function",
choices:["{}","()","!"],
answer: "()"
},
{
category:"food",
question:"best food?",
choices:["jamaican","haitian","spanish"],
answer:"jamaican"
},
{
category:"movie",
question:"fakest",
choices:["titanic","hunger games","jeff"],
answer:"titanic"
},
];
function getRandomQuestion(arr){
const questionSelect = Math.floor(Math.random()* arr.length);
return arr[questionSelect];
};
function getRandomComputerChoice(choicesArr){
let randomIndex = Math.floor(Math.random() * choicesArr.length);
return choicesArr[randomIndex];
}
function getResults(question, cpuChoice ){
if(cpuChoice === question.answer){
return "The computer's choice is correct!"
}else{
return `The computer's choice is wrong. The correct answer is: ${question.answer}`
}}
const randomQuestion = getRandomQuestion(questions);
const computerChoice = getRandomComputerChoice(randomQuestion.choices);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36
Challenge Information:
Build a Quiz Game - Build a Quiz Game