I am trying to create a function q generates 10000 random words with 3 to 5 characters, but only this passing a word

Asked

Viewed 486 times

-4

function textoAleatorio(){
    var letras = 'abcdefghijklmnopqrstuvwxyz';
    var aleatorio = '';
    for (var i = 0; i < 5 ; i++) {
        var rnum = Math.floor(Math.random() * letras.length);
        aleatorio += letras.substring(rnum, rnum + 1);

    }
    return aleatorio;
}
console.log(textoAleatorio())
  • Well, you’re only calling the function 1 time... To generate 10,000 words, you’d need to call it 10,000 times (within a loop of repetition, obviously).

1 answer

-4

for (var j = 0; j < 10000 ; i++) { 
   console.log(textoAleatorio());
}

It lacked a looping like this, to call this function 10000 times, more still would be to greatly improve the dynamics, and optimize all the code...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.