0

helpz!

how to generate random string? Example i have A, E, I, O, U whenever i run the code the output will be one of those letter wether it is A, E, I, O or U

23rd May 2017, 9:05 AM
boyd
boyd - avatar
4 Answers
+ 5
https://www.sololearn.com/discuss/333866/?ref=app please edit the title of your question. "helpz!" is not that good. furthermore you already used it before... to your question: generate a random number from 1 to 5 and use switch case to output the letter.
23rd May 2017, 9:16 AM
Mario L.
Mario L. - avatar
+ 2
var arr = [ "a","e","i","o","u"]; var rand = Math.floor(Math.random() * arr.length); console.log(arr[rand]);
23rd May 2017, 10:24 AM
Apel Mahmod
Apel Mahmod - avatar
+ 2
I made this function for your case. Check it out(: https://code.sololearn.com/WDGN0BEk92hW/?ref=app
23rd May 2017, 10:28 AM
Tim G
Tim G - avatar
+ 1
Put these characters into an array and generate a random number from 0 to the array length - 1 and use it as an array index.
23rd May 2017, 9:15 AM
Tamás Mazuk
Tamás Mazuk - avatar