+ 1

HELP AT MY CODE ! URGENT

hey you i new at javascript and i need your HELP !! i want to do like that ---> var Random = Math.floor(Math.random() * passW1.length * 7) ---> I WANT TO MATH.RANDOM CHOOSE 7 VALUES OF passW1 but when i put like on up code doesnt work ! ---------------THE CODE--------------------------------------------------------------------------------- var passW1 = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "K", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "k", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "*", "&", "%", "_", "-", ".", ",", ":", "~"]; var Random1 = Math.floor(Math.random() * passW1.length); function go() { var final = alert('Your PassWord is ' + passW1[Random1]); }

23rd Jul 2017, 7:58 PM
Carlos Castro
Carlos Castro - avatar
4 Answers
+ 3
I didn't ran the code but it looks like you need to add a for loop! In the code you're showing up, you only pick one letter so you have to repeat the process 7 time. Try this : var passW1 = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "K", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "k", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "*", "&", "%", "_", "-", ".", ",", ":", "~"]; var pwd = '' for(let i=0;i<7;i++){ var rdmNbr = Math.floor(Math.random()*passW1.length) pwd += passW1[rdmNbr] } console.log(pwd)
23rd Jul 2017, 8:52 PM
Drax
Drax - avatar
+ 2
@Drax that dude that work ! i will put your profile at my code !!!
23rd Jul 2017, 9:01 PM
Carlos Castro
Carlos Castro - avatar
+ 2
Please, don't post same question many times: https://www.sololearn.com/Discuss/558325/?ref=app ^^ (check my answer in your other thread ;))
24th Jul 2017, 3:50 AM
visph
visph - avatar
+ 1
Thanks, my pleasure 😊
23rd Jul 2017, 9:02 PM
Drax
Drax - avatar