Hi! I am working on this password generator solo project .I got to make the passwords but the generated passwords keep accumulating instead of resetting and displaying a new set of passwords. Please help . I cant figure out where i went wrong.
Yeah. You can either clear them at the top of the generate function, or you can, when building the password string, instead of concatenating, place them at the index using your loop variable.
Just to be clear, a better design would be to have your generate function return a string that gets assigned in your variable (youâd do it 4 times, or maybe have them in an array) and then those get passed to your render function. Iâd wrap that all in a function like âgetNewPasswordsâ and just call that. Try to avoid global variables. Theyâre often trouble.
Sure. I wrote this out, based on what you had. Basically I just applied some principles of functional programming. In retrospect, I may have jazzed it up too much, using too much ES6 and stuff. But this is pretty close to how I would have done it. It tightens it up and removes some of the repetition. The functions donât require any global variables (except for constants in SCREAMING_SNAKE_CASE) and they have no side effects (they donât mutate any variables outside of their scope . I think it is more readable this way, too. Itâs just a different way of thinking, it takes practice.