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

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

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 Report

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