Tell us what’s happening:
I don’t undertand user storie of getRandomComputerChoice. I know that I need to get the array choices of the selected object of the array questions and get just one random, but I don’t understand how to connect them. Maybe I am seeing with a perspective that I shouldn’t.
Your code so far
const questions = [
{
category: "Food",
question: "Fav food?",
choices: ["Pasta","Pizza","Burger"],
answer: "Pasta",
},
{
category: "Car",
question: "Fav car?",
choices: ["BMW","SEAT","OPEL"],
answer: "SEAT",
},
{
category: "Footbal Team",
question: "Fav Football Team?",
choices: ["Real Madrid","Barcelona","Las Palmas"],
answer: "Las Palmas",
},
{
category: "Brand Clothes",
question: "Fav Brand Clothes?",
choices: ["Nike","Adidas","Supreme"],
answer: "Nike",
},
{
category: "Music Genre",
question: "Fav Music Genre?",
choices: ["Reggaeton","Trap","Rap"],
answer: "Reggaeton",
},
];
function getRandomQuestion(arrQuestions) {
return arrQuestions[Math.floor(Math.random() * arrQuestions.length)];
}
function getRandomComputerChoice(arrChoices) {
const getChoices = Math.floor(Math.random() * arrChoices.length)
console.log(getChoices)
return arrChoices[getChoices].choices
}
function getResults() {
}
console.log(getRandomQuestion(questions))
console.log(getRandomComputerChoice(questions))
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36
Challenge Information:
Build a Quiz Game - Build a Quiz Game