School Catalogue Project Bug?

Hi, when I checked the solution video to compare my work, I noticed that the Setter for numberOfStudents is where they’re checking whether or not the value entered is a number. I’ve tried to do it this way as well but I can’t just get the (function If) inside the mentioned Setter to start.

I’ve tried to set a String just to trigger the warning, but it won’t even run through the (function If) nested in the Setter.

-------------Main Class

class School{
    this._name = name;
    this._level = level;
    this._numberOfStudents = numberOfStudents;
  get name(){
    return this._name;
  get level(){
    return this._level;
  get numberOfStudents(){
    return this._numberOfStudents;

//This is where I believe the issue is at.

  set numberOfStudents(value){
    if(typeof value !== 'number'){
      console.log('it is NOT a number')  
      this._numberOfStudents = value;
    console.log(`${} educates ${this.numberOfStudents} students at the ${this.level} school level.`)

  static pickSubstituteTeacher(substituteTeachers){
    let random = Math.floor(Math.random()*((substituteTeachers.length)-0));
    return substituteTeachers[random];

//Sub class Primary

class Primary extends School{
  constructor(name, numberOfStudents, pickupPolicy ){
    super(name, 'Primary', numberOfStudents);
    this._pickupPolicy = pickupPolicy;

  get pickupPolicy(){
    return this._level;

//Instance creation
//(Notice I’m sending a letter ‘a’ hoping it would trigger the number warning but it just sets it as an attribute)

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




I cannot see where you are using the setter in the first place. If you are talking about this instanciation

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

This never runs through the setter but is directly assigned by the constructor.

Please wrap your code in three backticks at the start and the end each in order to make it better readable.

1 Like

I apologize it’s been a while… hope you can read it better now.

Yes. But my answer stays the same: You don’t use the setter. If you want to test it, you could assign number of students like this:

lorraineHansbury.numberOfStudents = 'a'
1 Like

I agree with you, or I could create a method inside Object School… but this is the solution they’re providing in the vid for the lecture… should I mark it as a bug and have them check it out then?

What would you say is the bug? The setter is there and it is working fine. It is up to you to make use of it.

I guess bug is the wrong term, I just don’t agree with the answer that’s presented in the video, since he didn’t even use that function in the setter, just makes it to be as if the code is working 100% fine and the value inputted for number of students has been checked as a number.

I’ll leave it as an opinion but I’d appreciate feedback on this.

1 Like

You could post that in the category “suggestions” maybe.
There are many users in the forums asking about the use of setters and getters and a little more explanation may be useful.

1 Like

will leave this posted here for a little while, I’d like to read more opinions on this… I believe to have a good understanding on getters and setters which is why this was bugging me so much. I appreciate your feedback, will move on with the lecture.

1 Like

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