Tell us what’s happening:
i can’t understand why is my program has an error on test 13. if you can help me i would be thankful.
Your code so far
const questions = []
const questionOne={
category:"movie",
question:"what is faezeh's favorit movie?",
choices:["got","the100","walking dead"],
answer:"got",
}
const questionTwo={
category:"food",
question:"what is faezeh's favorit food?",
choices:["dolme","pizza","sushi"],
answer:"sushi",
}
const questionThree={
category:"sport",
question:"what is faezeh's favorit sport?",
choices:["tkd","bodybuilding","footbal"],
answer:"tkd",
}
const questionFour={
category:"friend",
question:"what is faezeh's favorit friend?",
choices:["zahra","sogand","nikoo"],
answer:"zahra",
}
const questionFive={
category:"music band",
question:"what is faezeh's favorit music band?",
choices:["nirvana","bts","palay royals"],
answer:"palay royals",
}
questions.push(questionOne,questionTwo,questionThree,questionFour,questionFive);
// console.log(questions)
//7
function getRandomQuestion(arr){
const randomArray= arr[Math.floor(Math.random()*arr.length)]
return randomArray;
}
//8
function getRandomComputerChoice(choicesArr){
const randomArray= choicesArr[Math.floor(Math.random()*choicesArr.length)]
return randomArray;
}
// console.log(getRandomComputerChoice(questionFive.choices))
//9
function getResults(question,pcChoice){
if(question.category==="music band" && pcChoice==="palay royals") return "The computer's choice is correct!"
else if (question.category==="music band" && pcChoice!=="palay royals") return `The computer's choice is wrong. The correct answer is: ${question.answer}`
else if ((question.category==="friend" && pcChoice==="zahra"))return "The computer's choice is correct!"
else if (question.category==="friend" && pcChoice!=="zahra") return `The computer's choice is wrong. The correct answer is: ${question.answer}`
else if ((question.category==="sport" && pcChoice==="tkd"))return "The computer's choice is correct!"
else if (question.category==="sport" && pcChoice!=="tkd") return `The computer's choice is wrong. The correct answer is: ${question.answer}`
else if ((question.category==="food" && pcChoice==="sushi"))return "The computer's choice is correct!"
else if (question.category==="food" && pcChoice!=="sushi") return `The computer's choice is wrong. The correct answer is: ${question.answer}`
else if ((question.category==="movie" && pcChoice==="got"))return "The computer's choice is correct!"
else if (question.category==="movie" && pcChoice!=="got") return `The computer's choice is wrong. The correct answer is: ${question.answer}`
}
console.log(getResults(getRandomQuestion(questions),getRandomComputerChoice(getRandomQuestion(questions).choices)))
// console.log(getResults(getRandomQuestion(questions),getRandomComputerChoice(getRandomQuestion(questions).choices)))
// console.log(getResults(getRandomQuestion(questions),getRandomComputerChoice(getRandomQuestion(questions).choices)))
// console.log(getResults(getRandomQuestion(questions),getRandomComputerChoice(getRandomQuestion(questions).choices)))
// console.log(getResults(getRandomQuestion(questions),getRandomComputerChoice(getRandomQuestion(questions).choices)))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:152.0) Gecko/20100101 Firefox/152.0
Challenge Information:
Build a Quiz Game - Build a Quiz Game