NEED YOUR HELP ! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

NEED YOUR HELP !

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, 8:40 PM
Carlos Castro
Carlos Castro - avatar
12 Answers
+ 8
Yeah but it reduces engagitivity. Even I stopped reading your solution from halfway as it captures less attention. This is also why many answers by me are quite short.
24th Jul 2017, 5:21 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 6
You could use a for loop
23rd Jul 2017, 8:58 PM
The Coding Sloth
The Coding Sloth - avatar
+ 4
You array (refering to the password generator code in you playground) seems to have repeated letters (k and K) and missing some characters (q and Q as letters, and other signs..). To list them, you can run this 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 i=passW1.length; var k=[]; while (i--) { k.push(passW1[i].charCodeAt(0)); } k.sort(function(a,b) { return a-b; }); i=k.length; var j=-1; while(i--) { if (j!=-1) { if (k[i]==j) document.write('repeat: '+k[i]+' '+String.fromCharCode(k[i])+'<br>'); else if (k[i]!=j-1) { document.write('hole between: '+k[i]+' '+String.fromCharCode(k[i])+' and '+j+' '+String.fromCharCode(j)+' :'); for (var n=k[i]+1; n<j; n++) document.write(' '+String.fromCharCode(n)); document.write('<br>'); } } j = k[i]; } So, I will suggest few things: + use a String (array like) instead an array of string to store individual characters + rather store forbiden chars instead of allowed (less longer) Well, implementing these few things, and forbiden chars based on those not used in your code, will give: var rc, p ='', n = 7, forbidenchars = '{|}q`[\\]^Q;<=>?@/+\'()'; while (n--) { do rc = String.fromCharCode(Math.floor(89*Math.random())+38); while (forbidenchars.indexOf(rc)!=-1) p += rc; } document.write('<br>'+p+'<br><br>');
24th Jul 2017, 3:36 AM
visph
visph - avatar
+ 4
Long answers aren't a problem if they are relevant, isn't it? ;P
24th Jul 2017, 3:46 AM
visph
visph - avatar
+ 3
so i need to do that: var Random1 = Math.floor(Math.random() * passW1.length); var Random1 = Math.floor(Math.random() * passW1.length); var Random1 = Math.floor(Math.random() * passW1.length); var Random1 = Math.floor(Math.random() * passW1.length); var Random1 = Math.floor(Math.random() * passW1.length); var Random1 = Math.floor(Math.random() * passW1.length); var Random1 = Math.floor(Math.random() * passW1.length); ?????? fuk
23rd Jul 2017, 8:49 PM
Carlos Castro
Carlos Castro - avatar
+ 2
you need to select 7 random character, otherwise it will output only one
23rd Jul 2017, 8:46 PM
voidneo
+ 2
That's one way, yep. var a = Math.floor( Math.random() * passW1.length ); var b = Math.floor( Math.random() * passW1.length ); alert( passW1[a] + passW1[b] );
23rd Jul 2017, 8:51 PM
voidneo
+ 2
ok i will try ! ty for help :3
23rd Jul 2017, 8:59 PM
Carlos Castro
Carlos Castro - avatar
+ 2
Make a string and add to it with a loop. Easy! var pass = ""; for (var x = 0; x <= 7; x++){ pass += (Math.floor(Math.random() * passW1.length)); } alert("Your password is: " + pass);
23rd Jul 2017, 9:01 PM
James
James - avatar
+ 2
Just giving correct code/answer will not teach anything... I wrote for those who are motivated to engage themselves into a learning path, as the name of this app'community is "solo-learn" ^^
24th Jul 2017, 6:29 AM
visph
visph - avatar
+ 1
when I was rewriting the code I found it very easy to do: https://code.sololearn.com/WQZByZcFFbcH/?ref=app I hope you like it, Please follow me.
23rd Jul 2017, 9:12 PM
Walid Kh. Sharaiyra
0
algo list of letters str for loop str+= random sel from list of letters alert str
24th Jul 2017, 6:39 AM
Abdur-Rahmaan Janhangeer
Abdur-Rahmaan Janhangeer - avatar