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

157
Views
Cómo spam números en javascript

Quiero que el script haga 1 2 3 4 5... Pero me da 499. Lo que necesito agregar al script no es agregar números sino solo imprimirlos

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

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>

Si desea un pequeño retraso en la impresión:

 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 Report

0

Su variable de spam se sobrescribe constantemente y al final del ciclo tiene el valor 499. Debe concatenar la variable consigo misma.

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

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