School Catalogue - WalkThrough Video - task 5 (setter) - number.isNaN() or isNaN(number)

Hello,
In the exercise School Catalogue after following the Walkthrough video for task 5, the programmer used the following code for the setter:

set numberOfStudents(number){
    if (number.isNaN()) {
      console.log('Invalid input: numberOfStudents must be set to a Number.')
    } else {
      this._numberOfStudents = number;
    }
  }

However that code did not work for me. it gave me the following TypeError:
Screen Shot 2020-05-03 at 14.04.20

I had to change it for the following code instead:

set numberOfStudents(number){
    if (isNaN(number)) {    //  line replaced
      console.log('Invalid input: numberOfStudents must be set to a Number.')
    } else {
      this._numberOfStudents = number;
    }
  }

I do not understand why the programmer’s code in the video does not work for me.

Thanks in advance for your help. Please find my complete code bellow:

// SCHOOL // Parent class
class School {
  constructor(name, level, numberOfStudents){
    this._name = name;
    this._level = level;
    this.numberOfStudents = numberOfStudents;
  }

  get name(){
    return this._name;
  }
  get level(){
    return this._level;
  }
  get numberOfStudents(){
    return this._numberOfStudents;
  }

  set numberOfStudents(number){
    if (number.isNaN()) {
      console.log('Invalid input: numberOfStudents must be set to a Number.')
    } else {
      this._numberOfStudents = number;
    }
  }

  quickFacts(){
    console.log(`${this.name} educates ${this.numberOfStudents} students at the ${this.level} school level.`)
  }
  static 
  pickSubstituteTeacher(substituteTeachers){
    let random = Math.floor(Math.random() * (substituteTeachers.length ));
    return substituteTeachers[random];
  }
}

//  PRIMARY SCHOOL  //  Child class
class PrimarySchool extends School {
  constructor(name,numberOfStudents,pickupPolicy){
    super(name, 'primary',numberOfStudents)
    this._pickupPolicy = pickupPolicy;  
  }
  get pickupPolicy(){
      return this._pickupPolicy;
  }
}

//  HIGH SCHOOL  //  Child class
class HighSchool extends School {
  constructor(name, numberOfStudents, sportsTeams){
    super(name, 'high', numberOfStudents);
    this._sportsTeams = sportsTeams;
  }
  get sportsTeams(){
    return this._sportsTeams;
  }
}

const lorraineHansbury = new PrimarySchool('Lorraine Hansbury', 514, 'Students must be picked up by a parent, guardian, or a family member over the age of 13.');

lorraineHansbury.quickFacts();

Could it be the video was reffering to a different command?
Their are two that are worded very similar.
It could also be an outdated video, though I don’t think that is likely.


Thanks for the links. I was not aware that Number.isNaN() exits. After going through the link for how to use Number.isNaN() I had noticed that in my code there was TypeError: for not using Number with capital N. However, after fixing that Error I gave it a try and change the integer for a string but it did not catch the error. The string was logged anyway. I tried two different ones but none of them work:
Number.isNaN()
Number.isNaN(number)

Can someone PLEASE tell me why my code does not work with:

Number.isNaN() or Number.isNaN(number) (it accepts any string when it shouldn’t)

It only works properly with isNaN(number)

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