Tell us what’s happening:
I keep failing tests 11, 12, 13, and 14.
I seem to be getting the appropriate responses for 12 and 13, so I’m assuming that there’s something wrong with the parameters I’m passing.
I’m also unsure of the problem with 14; I’ve tried both === and != in my comparisons.
(My questions are repeated, using numbers to help distinguish which one is being used and to ensure that the answer from one couldn’t be used in place for a different question.)
I may be misunderstanding the concept of the ‘object’ entirely, because I think I am passing the entire question object to getResults… unless I’m supposed to pass the entire questions array to that function?
Your code so far
function getRandomInt(max) {
return Math.floor(Math.random() * max);
}
const questions = [
{
category: "traffic",
question: "Do you stop at red lights? 1",
choices: ["yes1", "no1", "maybe1"],
answer: "maybe1"
},
{
category: "traffic",
question: "Do you stop at red lights? 2",
choices: ["yes2", "no2", "maybe2"],
answer: "maybe2"
},
{
category: "traffic",
question: "Do you stop at red lights? 3",
choices: ["yes3", "no3", "maybe3"],
answer: "maybe3"
},
{
category: "traffic",
question: "Do you stop at red lights? 4",
choices: ["yes4", "no4", "maybe4"],
answer: "maybe4"
},
{
category: "traffic",
question: "Do you stop at red lights? 5",
choices: ["yes5", "no5", "maybe5"],
answer: "maybe5"
}
];
function getRandomQuestion(questions) {
const chooseQuestion = Math.floor(Math.random() * questions.length);
return questions[chooseQuestion];
}
let selectedQuestion = getRandomQuestion(questions)
let availableChoices = selectedQuestion.choices
console.log(selectedQuestion)
console.log(selectedQuestion.question)
console.log(availableChoices)
function getRandomComputerChoice(choices) {
let chooseChoice = Math.floor(Math.random() * choices.length)
return choices[chooseChoice]
}
let computerChoice = getRandomComputerChoice(availableChoices)
let correctAnswer = selectedQuestion.answer
console.log(correctAnswer)
function getResults(questionObject, computerChoice) {
console.log(questionObject.answer);
console.log(computerChoice);
if (computerChoice != questionObject.answer) {
return console.log (`The computer's choice is wrong. The correct answer is: ${correctAnswer}`)
} else {
return console.log ("The computer's choice is correct!")
}
}
getResults(selectedQuestion, computerChoice);
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:152.0) Gecko/20100101 Firefox/152.0
Challenge Information:
Build a Quiz Game - Build a Quiz Game