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

156
Vistas
How to spam numbers in javascript

I want from script to do 1 2 3 4 5... But it give me 499. What I need to add to the script is not to add numbers but just to print them

function numbers() {
  for (let i = 0; i < 500; i++) {
    var spam = i + "<br>";
  }
  document.getElementById('demo20').innerHTML = spam;
}
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

function numbers() {
  const demo20 =  document.getElementById('demo20');
  for (let i = 0; i < 500; i++) {
   demo20.insertAdjacentHTML("beforeend", i + "<br>");
  }
}

numbers();
<div id="demo20"></div>

If you want a small delay in printing:

async function numbers() {
  const demo20 = getElementById('demo20');
  for (let i = 0; i < 500; i++) {
    demo20.getElementById('demo20').insertAdjacentHTML("beforeend", i + "<br>");
    await new Promise(res => setTimeout(res, 100));
  }
}

numbers();
<div id="demo20"></div>

about 4 years ago · Juan Pablo Isaza Denunciar

0

Your spam variable is constantly overwritten and at the end of the loop it has the value 499. You need to concatenate the variable with itself.

  var spam = "";
  for (let i = 0; i < 500; i++) {
    var spam += i + "<br>";
  }
about 4 years ago · Juan Pablo Isaza Denunciar

0

function numbers() {
  var spam = ''
  for (let i = 0; i < 500; i++) {
     spam += i + "<br>";
  }
  document.getElementById('demo20').innerHTML = spam;
}
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