Advanced Objects 5:Getters help


#1
  _model: '1E78V2',
  _energyLevel: 100,
  get energyLevel() {
    if (this._energyLevel && typeof number){
      return `My current energy level is ${this._energyLevel}`;
    } else {
      return 'System malfunction: cannot retrieve energy level';
    }
   }
  }

i ran that code for the first and second exercise and it worked. but now the third exercise wants me to write the else statement. now this error pops up. ( Did you use an if statement to check if this._energyLevel is a number?: expected ‘My current energy level is string’ to equal 'System malfunction) What am i doing wrong?


#2

if (typeof this._energyLevel === ‘number’)

Worked for me


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.