Tell us what’s happening:
I am unsure what am I doing wrong with getRandomComputerChoice and getResults
Your code so far
const array = []
let obj1 = {
category: "PD",
question: "What is your age?",
choices: ["12","42","56"],
answer: "42"
}
let obj2 = {
category: "PF",
question: "What is your name?",
choices: ["Josh","Sandy","Anthony"],
answer: "Josh"
}
let obj3 = {
category: "PD",
question: "What is your sex?",
choices: ["Male","Female","Trans"],
answer: "Male"
}
let obj4 = {
category: "PE",
question: "What is your work?",
choices: ["Engineer","Doctor","Lawyer"],
answer: "Doctor"
}
let obj5 = {
category: "PZ",
question: "Where is moon?",
choices: ["Outside Earth","Near Earth","Inside Earth"],
answer: "Near Earth"
}
const questions = [obj1,obj2,obj3,obj4,obj5]
console.log(questions)
function getRandomQuestion(arrayQuestions){
let randomNumber = Math.floor(Math.random() * (4 - 0 + 1)) + 0;
console.log(randomNumber)
return arrayQuestions[randomNumber]
}
console.log(getRandomQuestion(questions))
function getRandomComputerChoice(availableChoices){
let randomNumber = Math.floor(Math.random() * (3 - 0 + 1)) + 0;
console.log(randomNumber)
return availableChoices[randomNumber]
}
console.log(getRandomComputerChoice(obj5.choices))
function getResults(questionObj,computerChoice) {
if (computerChoice == questionObj.answer) {
return "The computer's choice is correct!";
}
else {
return `The computer's choice is wrong. The correct answer is: ${userAnswer}.}`;
}
};
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/155.0.0.0 Safari/537.36
Challenge Information:
Build a Quiz Game - Build a Quiz Game