Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

97
Views
El generador de preguntas aleatorias solo genera 1 pregunta en la matriz de objetos y sale del indicador. En lugar de hacer todas las preguntas
  • Creé una matriz de objetos, y selecciona aleatoriamente una pregunta de 1 de los objetos y la coloca en un cuadro de aviso.

  • Pero, solo genera 1 pregunta, y rompe el cuadro de aviso. No solicita todas las demás preguntas una tras otra.

 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 answers
Answer question

0

Si desea hacer todas las preguntas seguidas, necesita algún tipo de bucle. Aquí hay un ejemplo con un bucle while.

Esta pieza en su código no funcionará de todos modos porque no obtendrá la respuesta correcta la mayoría de las veces:

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

Si no desea hacer las preguntas en orden aleatorio, necesita un indicador de qué pregunta ya se hizo. Una idea simple es simplemente eliminar la pregunta formulada de la matriz.

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!