Classes Static Methods!11/12

I have a difficulty!!!

Please link to the exercise so we can have a look. Thanks.

return password[randomNumber]

That doesn’t look quite right.

static generatePassword() {
let password = Math.floor(Math.random()*10000);
if (password < 100) {
  password = '0' + password + Math.floor(Math.random() * 9);
  else if (password < 1000) {
  password = '0' + password;
  return password;
} else {
  return password;


thank you very much …

Paring down code to the least amount is how we prevent code bloat, and avoidable errors…

  static generatePassword() {
    return Math.floor(Math.random() * 10000)

We should not be logging inside the method if not absolutely necessary. It’s okay to store the random number in a variable and return that, but then why would we need to? The method name and code are descriptive enough.

1 Like