const questions =[
{
category: "cat",
question: "what?",
choices: ['a','b','c'],
answer: 'b'
},
{
category: "cat",
question: "is?",
choices: ['a','b','c'],
answer: 'a'
},
{
category: "cat",
question: "where?",
choices: ['a','b','c'],
answer: 'c'
},
{
category: "cat",
question: "when?",
choices: ['a','b','c'],
answer: 'a'
},
{
category: "cat",
question: "what?",
choices: ['a','b','c'],
answer: 'c'
}
]
function getRandomQuestion(arr){
return arr[Math.floor(Math.random() * arr.length)];
}
function getRandomComputerChoice(arr){
return arr.choices[Math.floor(Math.random() * arr.choices.length)];
}
function getResults(qu, choice){
if(qu.answer === choice){
return "The computer's choice is correct!";
}else{
return "The computer's choice is wrong. The correct answer is: " + qu.answer
}
}
const getQuestion = getRandomQuestion(questions);
const getChoice = getRandomComputerChoice(getQuestion);
console.log(getQuestion);
console.log(getChoice);
console.log(getResults(getQuestion,getChoice))
not sure if this intended but if getresult test case passes with just passing the object n then .answer shouldnt the getchoice also pass with just passing the object like:
function getRandomComputerChoice(arr){
return arr.choices[Math.floor(Math.random() * arr.choices.length)];
}
which result passing getchoies.choices instaed of just passing the obj as a whole
same with get result get result doesnt pass if i do
function getResults(qu, choice){
if(qu === choice){
return "The computer's choice is correct!";
}else{
return "The computer's choice is wrong. The correct answer is: " + qu
}
}
then just passing .answer as a param like with getchoice
curious one solution passes for one test case but doesnt pass for the other
basically get choices requires to take question.choices as a param but cant pass question but get result can pass question but cant take question.answer as a param
sorry not sure if i made sense i kinda got confused midway typing the question