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

143
Vistas
im trying to make a quiz for my bootcamp and i cant figure out what is wrong with the code

I'm trying to make a quiz game for a class and I can't seem to find the problem.

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;
}

This is the function and I have an array of objects, which is referenced in the "random" variable. I'm totally lost and I know I'm missing something simple. The purpose of this function is to display a random question from the array testQuestions.

almost 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Math is a global object and it starts with a capital M

Math.floor
almost 4 years ago · Santiago Trujillo Denunciar

0

You are adding the event listener inside the function. The function will only run if you call it, so the event listener will never be added. Additionally, document.write() will overwrite the entire page. I changed it to use document.createElement() and document.body.appendChild(). Change your code to this:

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 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