#Password Generator
6 messages · Page 1 of 1 (latest)
generatedPasswordOne += characters[randomChar1]
With this line and the analogous one for password two, remember that += basically means this:
In other words, make the password equal whatever is currently there plus the new character. And since this is inside a loop, it's going to do that for all 15 iterations of that loop. That's fine the first time someone presses the button, because at that point, the two passwords are just empty strings, but after the second press, there's already one or more passwords stored inside of the password variables, so they passwords just keep accumulating.
So here's the question I would ask yourself: how can you get back to that initial state that's working just fine with each press of the button and invocation of the functions in question?
*er, empty array, not empty string! But otherwise what I said is right!
Is this a liable solution? It worked but I don't know if it's right
Yeah, that's fine! What I had in mind was precisely this — "clearing out" the variables. I guess you could do it inside the getRandomCharOne and Two functions as well, but I don't think it makes a difference where you do it in this case.
Thank you very much for the help. Your explanation was super clear and just within minutes I found out what was wrong. Your insight really helped me a lot, have a good day!