I cannot pass 11 and 12 in this challange and I belive 11 is bugged because when I remove getResult function variables it sometimes checks it correct.
11. If the computer choice matches the answer, getResults
should return The computer's choice is correct!
12. 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.
My code as follows
let questions=[
{
category:"Spor",
question:"2024 Formula1 dünya şampiyonu kimdir?",
choices:["Max Verstappen", "Lewis Hamilton", "Lando Noris"],
answer:"Max Verstappen"
},
{
category:"Tarih",
question:"Parayı hangi millet icat etmiştir?",
choices:["Artuklar", "Lidyalılar", "Sümerler"],
answer:"Lidyalılar"
},
{
category:"Biyoloji",
question:"Hangi organımız kan pompalar?",
choices:["Böbrek", "Akciğer", "Kalp"],
answer:"Kalp"
},
{
category:"Coğrafya",
question:"Türkiyenin başkenti neresidir?",
choices:["Ankara", "Adana", "İstanbul"],
answer:"Ankara"
},
{
category:"Matematik",
question:"2+2 kaç eder?",
choices:["5", "3", "4"],
answer:"4"
}
];
//Selects random question object
function getRandomQuestion(questions){
let random = Math.floor(Math.random()*questions.length)
return questions[random]
}
let question = getRandomQuestion(questions)
//Selects random choice
let choices = question.choices
function getRandomComputerChoice(choices){
let random = Math.floor(Math.random()*choices.length)
return choices[random]
}
let choice = getRandomComputerChoice(choices);
//Checks result of the question
function getResults(choice, question){
if(question.answer==choice){
return "The computer's choice is correct!"
}else{
return `The computer's choice is wrong. The correct answer is: ${question.answer}`
}
}
console.log(question.question)
console.log(choice)
console.log(getResults(choice,question))