I am having issues with the Build a Quiz Game Lab.
For some reason, it is not passing the last 2 test cases for ensuring the two values being compared are using a strict equality comparison and the function returns the correct string when the computer is wrong. I added debugging messages in the program to ensure the right values are being stored throughout the program and don’t know why it’s failing.
I also noticed when I tried wrapping the correct answer in “< >” it wouldn’t output to the console which you can see if you log the code below into a terminal.
MY CODE:
const obj1 = {
category: "Coding Questions | obj1",
question: "Do you like JavaScript?",
choices: ["Yes", "No", "Absolutely"],
answer: "Absolutely"
};
const obj2 = {
category: "Coding Questions | obj2",
question: "Do you like JavaScript?",
choices: ["Yes", "No", "Absolutely"],
answer: "Absolutely"
};
const obj3 = {
category: "Coding Questions | obj3",
question: "Do you like JavaScript?",
choices: ["Yes", "No", "Absolutely"],
answer: "Absolutely"
};
const obj4 = {
category: "Coding Questions | obj4",
question: "Do you like JavaScript?",
choices: ["Yes", "No", "Absolutely"],
answer: "Absolutely"
};
const obj5 = {
category: "Coding Questions | obj5",
question: "Do you like JavaScript?",
choices: ["Yes", "No", "Absolutely"],
answer: "Absolutely"
};
const questions = [obj1, obj2, obj3, obj4, obj5];
function getRandomQuestion(questions) {
const min = 0;
const max = questions.length;
let objVal = Math.floor(Math.random() * (max - min) + min);
return questions[objVal];
}
const objChoice = getRandomQuestion(questions);
function getRandomComputerChoice(objChoicesArr) {
const min = 0;
const max = 3;
let choicesVal = Math.floor(Math.random() * (max - min) + min);
return objChoicesArr[choicesVal];
}
const objChoicesArr = objChoice.choices;
const objComputerChoice = getRandomComputerChoice(objChoicesArr);
function getResults(objChoice, objComputerChoice) {
if (objComputerChoice === objChoicesArr[2]) {
return "The computer's choice is correct!";
} else {
return `The computer's choice is wrong. The correct answer is: ${objChoice.choices[2]}`
}
}
// Debugging
console.log(objChoice);
console.log(objComputerChoice);
console.log(getResults(objChoice, objComputerChoice));
console.log("###### BREAK | BELOW IS DEBUGGING MESSAGE ######");
console.log("The computer's choice is wrong. The correct answer is: " + objChoice.choices[2] + ">");
console.log("The computer's choice is wrong. The correct answer is:" + "<" + objChoice.choices[2]);
console.log("The computer's choice is wrong. The correct answer is:" + "<" + objChoice.choices[2] + ">");
Challenge Information:
Build a Quiz Game - Build a Quiz Game
Failed Test Cases:
13. If the computer choice doesn’t match the answer, getResults should return The computer’s choice is wrong. The correct answer is: , where is the value of the correct answer to the chosen question.
14. Your getResults function should use exact equality comparison, not substring matching.