#Clearing text content of div to repeat function (Javascript)

6 messages · Page 1 of 1 (latest)

winter elbow
#

I'll try my best to describe the problem I have, it's a bit technical. I'm doing the password generator solo project, and I seem to have made it work (thankfully). But I need the text fields to clear when I press the "Generate passwords" again. Right now the randomly generated passwords are just stacked on top of each other each time I press the button. I've tried to search for it online but it seems too technical.

Codepen link:
https://codepen.io/ifeoluwa-medeyinlo/pen/zYJNLqG

Thanks.

narrow owl
#

I didn’t read your code but try setting innerText to “” at the beginning of the function

unkempt nova
#

In both the functions which generate the passwords you need to first clear the existing passwords before generating the one ones.

fieldOne.textContent = ''

narrow owl
#

So when the function is calledagain you start with a blank space

#

Bill’s too quick for me 😂

unkempt nova
#

I would also suggest refactoring your code a little bit... it seems a little clunky to to call generatePasswords() which will generate the first password then make a call to generateSecondPassword()...

Instead try to make it work (not complete code) with something like this:

function generatePasswords() {
  fieldOne.textContent = generatePassword();
  fieldTwo.textContent = generatePassword();
}