Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

105
Vistas
The random question generator is only prompting 1 question in the array of objects, and exiting the prompt. Instead prompting all the questions
  • I created an array of objects, and it randomly picks a question out of 1 of the objects and puts in in a prompt box.

  • But, its only prompting 1 question, and it breaks out the prompt box. It doesn't prompt all the other questions 1 after another.

let theQuestions = [

     {
        question: "What is the capital of Georgia?", 
        answer:     "atlanta"
     },

     {
        question: "What is the name of the Atlanta Baseball Team?", 
        answer:   "atlanta braves"
     },

     {
        question: "How many rings have the Atlanta Falcons Won?", 
        answer:   0
     },

     {
        question: "What is the name of the NBA team in Miami?", 
        answer:   "miami heat"
     }

];// theQuestions array

const randomQuestions = ()=>{
  const random = Math.floor(Math.random() *theQuestions.length);
  return theQuestions[random];

}// randomQuestions



let question = randomQuestions().question;
let answer  = randomQuestions().answer;


const askQuestions = prompt(question);
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If you want to ask all questions in a row you need some kind of loop. Here is an example with a while loop.

This piece in you code wont work anyway because you wont get the right answer most of the times:

let question = randomQuestions().question;
let answer  = randomQuestions().answer;

If you wan't to ask the questions in a random order you need an indicator which question was already asked. A simple idea is to just remove the asked question from the array.

let theQuestions = [
  { question: "What is the capital of Georgia?", answer: "atlanta" },
  { question: "What is the name of the Atlanta Baseball Team?", answer: "atlanta braves" },
  { question: "How many rings have the Atlanta Falcons Won?", answer: 0 },
  { question: "What is the name of the NBA team in Miami?", answer: "miami heat" }
];

const randomQuestions = () => {
  const index = Math.floor(Math.random() * theQuestions.length);
  const question = theQuestions.splice(index, 1);
  return question[0];

}

while(theQuestions.length) {
  const question = randomQuestions();
  const askedQuestion = prompt(question.question);
  if (askedQuestion === null) {
    console.log("User clicked cancel");
  } else {
    console.log(askedQuestion.toLowerCase() === question.answer);
  }
}

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda