Tell us what’s happening:
I can’t seem to get any user stories to pass, It even fails to acknowledge my array! Pls if u can help point out something wrong in the code, I’ve been here for hours.
The only feedback I’ve gotten is that the .length property is unreadable or something, but like .length are allowed in arrays so…
Your code so far
const questions = [
{category: "Colours", question:"Which is a primary colour?", choices: ["Purple", "Blue", "Orange"], answer: "Blue"},
{category: "Shapes", question: "Which is not a polygon?", choices: ["Circle", "Square", "Triange"], answer: "Cirlce"},
{category: "Numbers", question: "Which of the following is an odd number?", choices: ["12", "47", "106"], answer: "47"},
{category: "Animals", question: "Which animals is canivorous?", choices: ["Giraffes", "Crocodiles", "Pigs"], answer: "Crocodiles"},
{category: "Plants", question: "Which plant is a flower?", choices: ["Bromeliads", "Eggplant", "Marigold"], answer: "Marigold"}
];
// Random Question function below
function getRandomQuestion(questions) {
let run = Math.round(Math.random() * questions.length);
return run.question;
}
// To Choose a questions object at random
const randQuest = Math.round(Math.random() * questions.length);
// Choice of the random question object
const randCh = questions[randQuest.choices];
function getRandomComputerChoice(randCh) {
return Math.round(Math.random() * randCh.length);
}
let compCh = getRandomComputerChoice(randCh);
function getResults(randQuest, compCh) {
let ans = randQuest.answer;
if(compCh === ans) {
return "The computer's choice is correct!";
} else {
return `The computer's choice is wrong. The correct answer is: ${ans}`
}
};
console.log(getRandomQuestion(questions));
console.log(getRandomComputerChoice(randCh));
console.log(getResults(randQuest, compCh));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36
Challenge Information:
Build a Quiz Game - Build a Quiz Game