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

141
Views
estoy tratando de hacer una prueba para mi bootcamp y no puedo averiguar qué está mal con el código

Estoy tratando de hacer un juego de preguntas para una clase y parece que no puedo encontrar el problema.

 function askQuestions(random) {
 var random = math.floor(math.random() * testQuestions.length);
 var start = document.getElementById(testStart);
 start.addEventListner('click', askQuestions);

 if (start) {
 document.write(random);
 }
 return;
}

Esta es la función y tengo una matriz de objetos, a la que se hace referencia en la variable "aleatoria". Estoy totalmente perdido y sé que me estoy perdiendo algo simple. El propósito de esta función es mostrar una pregunta aleatoria de la matriz testQuestions .

almost 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Math es un objeto global y comienza con una M mayúscula

 Math.floor
almost 4 years ago · Santiago Trujillo Report

0

Está agregando el detector de eventos dentro de la función. La función solo se ejecutará si la llama, por lo que nunca se agregará el detector de eventos. Además, document.write() sobrescribirá toda la página. Lo cambié para usar document.createElement() y document.body.appendChild() . Cambia tu código a este:

 function askQuestions(random) {
 var random = Math.floor(Math.random() * testQuestions.length);
 var el = document.createElement('p');
 el.textContent = random.toString();
 document.body.appendChild(el);
}

var start = document.getElementById(testStart);
start.addEventListner('click', askQuestions);
almost 4 years ago · Santiago Trujillo 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!