Estoy probando un poco de codificación y me gustaría que las cadenas de 30 caracteres aparezcan en intervalos de 1 segundo una tras otra cuando se inicia el código. Probé setInterval & setTimeout y no pude hacerlo funcionar. Si alguien pudiera ayudarme sería muy apreciado.
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 }setInterval(code, time);esta función te permitirá esperar X milisegundos antes de ejecutar el código definido.
aquí, el código correcto, y arreglé un poco tu formato.
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" } por cierto, probablemente querías reemplazar characters.length . longitud dentro de tu ciclo for por: cadena_longitud para usar el parámetro de la función (que en realidad nunca usaste)