Classes Static Methods!11/12


#1

I have a difficulty!!!


#2

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

return password[randomNumber]

That doesn’t look quite right.


#3

https://www.codecademy.com/courses/learn-javascript-classes/lessons/classes/exercises/static-methods?action=resume_content_item&course_redirect=introduction-to-javascript


#4
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;
}

I FOUND!!!


#5

thank you very much …


#6

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.