Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

157
Visualizações
How can I make a set of numbers increase every second and for each increment, print the current set on a new line?

I have these set of 11 numbers that increase per second, but I want each increment or the current set of numbers to write on a new line. E.g;

20220215155

20220215156

20220215157 etc...

I tried adding the n tag buh it returned an error.

var i = 20220215155
    function increment() {
    i+, + </n>;

document.getElementById('test').innerHTML = i
     }
  ('increment()', 1000);

Please I really need help as I have been trying to get this for so long.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Your code is not valid JS

Here is something that does work - I am using setInterval here

var i = 20220215155

function increment() {
  i++; // increment
  document.getElementById('test').innerHTML += i + "<br/>"; // add it with a breakline
}
setInterval(increment, 1000);
<div id="test"></div>

You can use a template literal for the string too

`${i}<br/>`
about 4 years ago · Juan Pablo Isaza Relatório

0

You can use setTimeout to call the function after a set time while also increasing the number you initially pass into the function.

// Cache the element
const test = document.querySelector('#test');

let n = 20220215155;

// `increment` accepts `n` as an argument
function increment(n) {

  // Add a new HTML string to the element
  test.innerHTML += `${n}</br>`;

  // Call the function again with an new `n`
  setTimeout(increment, 1000, ++n);
}

increment(n);
<div id="test"></div>

Additional documentation

  • Template/string literals
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda