Cuéntanos qué está pasando:
According to point 4, the ‘question’ key must have a string value representing a question. If you check my work, you will see that it is indeed a string representing a question. I don’t understand why the validator is throwing an error; I’ve tested my code in VS Code and it works perfectly. The validator is being too rigid.
Tu código hasta el momento
const questions = [
{
category: "Question",
question: "Who is the villain in Resident evil 3?",
choices: ["Lady Dimitrescu", "Ramon Salazar", "Nemesis"],
answer: "Nemesis"
},
{
category: "Question",
question: "Who is the new protagonist of Resident Evil Requiem",
choices: ["Rebecca Chambers", "Jill Valentine", "Grace Ashcroft"],
answer: "Grace Ashcroft"
},
{
category: "Question",
question: "What is the main virus in the saga?",
choices: ["Uroboros", "Las plagas", "Virus-T"],
answer: "Virus-T"
},
{
category: "Question",
question: "Who is the main and most powerfull villain in the saga?",
choices: ["Oswald Spencer", "Alex Wesker", "Albert Wesker"],
answer: "Albert Wesker"
},
{
category: "Question",
question: "Who is the protagonist of resident evil 2 and 4?",
choices: ["Chris Redfield", "Carlos oliveria", "Leon S. Kennedy"],
answer: "Leon S. Kennedy"
}
];
function getRandomQuestion(questionArr) {
const randomIndex = Math.floor(Math.random() * questionArr.length);
return questionArr[randomIndex];
}
function getRandomComputerChoice(choiceArr) {
const randomIndex = Math.floor(Math.random() * choiceArr.length);
return choiceArr[randomIndex];
}
function getResults(questionObject, computerChoice) {
if (computerChoice === questionObject.answer) {
return "The computer's choice is correct!";
}
else {
return `The computer's choice is wrong. The correct answer is: ${questionObject.answer}`
}
}
const randomQ = getRandomQuestion(questions);
const computerChoice = getRandomComputerChoice(randomQ.choices);
console.log("Question:", randomQ.question);
console.log("Computer chose:", computerChoice);
console.log(getResults(randomQ, computerChoice));
Información de tu navegador:
El agente de usuario es: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36
Información del Desafío:
Construir un Juego de Preguntas y Respuestas. - Construir un Juego de Cuestionario