School Catalogue Project

Hi,

First post on here but I’m slightly stuck on the School Catalogue project. Everytime I call .quickFacts on an instance the string returns the expected values except for the numberOfStudents, which returns undefined.

Have tried restructuring and changing the syntax but with no luck. Any ideas?

Thanks in advance,

HW.

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

  get name() {
    return this._name;
  }

  get level() {
    return this._level;
  }

  get numberOfStudents() {
    return this._numberOfStudents;
  }

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

  quickFacts() {
    console.log(`${this._name} educates ${this._numberOfStudents} at the ${this._level} school level.`)
  };

  static pickSubstituteTeacher(substituteTeachers){
    const randNum = Math.floor(Math.random() * substituteTeachers.length);
    return substituteTeachers[randNum];
  }
}

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

  get pickupPolicy() {
    return this._pickupPolicy;
  }
}

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();

const sub = School.pickSubstituteTeacher(['Jamal Crawford', 'Lou Williams', 'J. R. Smith', 'James Harden', 'Jason Terry', 'Manu Ginobli']);

const alSmith = new HighSchool('Al E. Smith', 415, ['Baseball', 'Basketball', 'Volleyball', 'Track and Field']);
alSmith.quickFacts();
console.log(alSmith.sportsTeams);

Looking a the constructor which should set the property:

  constructor(name, level, numberOfStudents) {
    this._name = name;
    this._level = level;
    this._numberOfStudents;
  }

I do spot a problem right of the bat.

1 Like

Don’t know how I missed, that! :man_facepalming:

Thanks!

Teaching yourself steps to catch/debug this kind of errors is really useful. To walk through your code. So in this case you would start here:

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.');

then look at the primary school constructor, followed by the School constructor and so forth. You can then of course add .log() to any step to see what your code is actually doing (or use a debugger)

2 Likes

Thanks for the help,

Starting to realise the skill of debugging is going to be just as or more valuable than actually creating the code. Good place to start!

HW

2 Likes

Programming is so much more then coding. Being able to get client requirements (what they want build), translating that into maintainable code. Being able to debug, logging in case something goes wrong in production. And so much more

so much to look forward too :slight_smile:

1 Like