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

137
Visualizações
How do I make my JavaScript loop run slower

I am trying a little bit of coding and I would like for the 30 character strings to appear in the 1 second intervals one after another when the code is started. I tried setInterval & setTimeout and I couldn't get it to work. If someone could please help that would be much appreciated.

count = 0
while (count < 200) {
    console.log(create_random_string(30))

function create_random_string(string_length){
    var random_string = '';
    var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz'
    for(var i, i = 0; i < characters.length; i++){
        random_string += characters.charAt(Math.floor(Math.random() * characters.length))
    }
    return  "|BTC| " + random_string +  "  | " + " PRIVATNI KLJUČ NIJE ISPRAVAN" + "  | " + " STANJE: 0.00"
}
count = count + 1
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

setInterval(code, time); 

this function will allow you to wait X miliseconds before running the code defined.

here, the correct code, and i fixed your formatting a bit.

let count = 0;
while (count < 200) {
    setTimeout(
        function() { console.log(create_random_string(30)); }
        , 500);
    count++;
}

function create_random_string(string_length){
    var random_string = '';
    var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz'
    for(var i, i = 0; i < characters.length; i++){
        random_string += characters.charAt(Math.floor(Math.random() * characters.length))
    }
    return  "|BTC| " + random_string +  "  | " + " PRIVATNI KLJUČ NIJE ISPRAVAN" + "  | " + " STANJE: 0.00"
}

by the way, you probably wanted to replace characters.length inside your for loop for : string_length to use the fuction's parameter (which you never actually used)

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