hi developers i had written a code for quiz app but the last case was did not passed i have obsorve the code is correct but i did not understand what is the mistake in this code please help me please check my code once and help me.
const questions = [
{
category: "PCo",
question: "fav color ?",
choices: ['Red', 'Black', 'Both'],
answer: 'Red'
},
{
category: "PCa",
question: "Fav car ?",
choices: ['Honda', 'BMW', 'both'],
answer: 'Honda'
},
{
category: "PB",
question: "Fav brand ?",
choices: ['Amazon', 'Google', 'Both'],
answer: 'Both'
},
{
category: "PF",
question: "Fav fruit ?",
choices: ['Apple', 'Grapes', 'Mango'],
answer: 'Mango'
},
{
category: "PH",
question: "fav hobby ?",
choices: ['Singing', 'Coding', 'Both'],
answer: 'Both'
}
];
const getRandomQuestion = (questions) => {
let randomNumber = Math.floor(Math.random()) * 4;
return questions[randomNumber]
}
const getRandomComputerChoice = (choices) => {
let randomNumber = Math.floor(Math.random()) * 4;
return choices[randomNumber]
}
const getResults = (questionObj , comChoice) => {
let randomNumber = Math.floor(Math.random()) * 4;
questionObj = questions[randomNumber];
if(questionObj.answer === comChoice){
return `The computer's choice is correct!`
} else {
return ` The computer's choice is wrong. The correct answer is: ${ questionObj.answer } `
}
}
console.log(getResults(questions,'black'))
test case and bug :
13. If the computer choice doesn't match the answer,
getResults
should return
The computer's choice is wrong. The correct answer is: <correct-answer>
where
<correct-answer>
is the value of the correct answer to the chosen question. // tests completed // console output The computer's choice is wrong. The correct answer is: Red