Build a Password Generator App Help

Hi all,

I am trying to complete the Build a Password Generator App Lab, below is my current code but I am failing on test 8 -

  • You should call the generatePassword function with a numeric argument and store the returned password in the password variable.

I can’t for the life of me see why, can anyone point me in the right direction?

let generatePassword = (length) =>{
  let output ="";
  let characters="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()"
  for (let i = 0; i < length; i++){
    output += characters[Math.floor(Math.random()*characters.length)];
  }
  return output
}
let  password = ""

password = generatePassword(4);
console.log(`Generated password:${password}`);

Thanks

I would put this on one line. Generally, its best to put directly into the variable what you want to go there instead of initializing it with a value you do not want.

1 Like

Thanks JeremyLT, seems so obvious now!

1 Like