Tell us what’s happening:
I have problems with the functions. I read the familiar questions and I tried different codes but it doesn’t work.
The console.logs of function 1 und 2 show the correckt results but I didn’t pass tasks 8 to 14.
Can you guys give me tips or hints, please?
Your code so far
const questions = [];
const questions1 = {
category: "Question 1:",
question: "When starts WW2?",
choices: ["1928", "1918", "1939"],
answer: "1939",
};
const questions2 = {
category: "Question 2:",
question: "Who was not a german president?",
choices: ["Angela Merkel", "Friedrich Merz", "Sido Aggro"],
answer: "Sido Aggro",
};
const questions3 = {
category: "Question 3:",
question: "Which is not a primary color?",
choices: ["red", "green", "yellow"],
answer: "green",
};
const questions4 = {
category: "Question 4:",
question: "Which language is a programming language?",
choices: ["HTML", "CSS", "JavaScript"],
answer: "JavaScript",
};
const questions5 = {
category: "Question 5:",
question: "What is the heighest mountain in europe?",
choices: ["Mont Blanc", "Zugspitze", "Matternhorn"],
answer: "Mont Blanc",
};
questions.push(questions1, questions2, questions3, questions4, questions5);
function getRandomQuestion(question) {
let getquestion = Math.floor(Math.random() * questions.length);
return questions[getquestion].question;
}
console.log(getRandomQuestion())
console.log(getRandomQuestion())
console.log(getRandomQuestion())
function getRandomComputerChoice(choices) {
let getchoices = Math.floor(Math.random() * questions.length);
return questions[getchoices].answer;
};
console.log(getRandomComputerChoice())
console.log(getRandomComputerChoice())
console.log(getRandomComputerChoice())
console.log(getRandomComputerChoice())
function getResults(question, choices) {
if(questions.question === choices.answer) {
return "The computer's choice is correct!";
} else `The computer's choice is wrong. The correct answer is: ${questions.answer}`;
}
console.log(getResults(1, 2))
console.log(getResults(2, 4))
console.log(getResults(1, 1))
I also tried this function what was in other forum sections:
but the console only shows “undefined”
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36
Challenge Information:
Build a Quiz Game - Build a Quiz Game