School Catalogue

Hi! I have a problem with this exercise!
When i call quickFacts() the result is :undefined educates undefined students at the undefined school level.
But i don’t understand why!
Can we help me?
This is the code:

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(numberOfStudents){
    if (typeof numberOfStudents === 'num'){
      this._numberOfStudents = numberOfStudents
    } else {console.log('Invalid input: numberOfStudents must be set to a Number.')}
 static quickFacts(){
     console.log(`${this._name} educates ${this._numberOfStudents} students at the ${this._level} school level.`);
  static pickSubstituteTeacher(substituteTeachers){
   const randomNumber = Math.floor(Math.random()*substituteTeachers.length-1);
    return substituteTeachers[randomNumber] 

class Primary extends School{
  constructor(name, level, numberOfStudents, pickupPolicy){
    super(name, level, numberOfStudents)
    this._pickupPolicy = pickupPolicy
  get pickupPolicy(){
    return this._pickupPolicy
class Middle extends School{
  constructor(name, level, numberOfStudents){
    super(name, level, numberOfStudents)
class High extends School{
  constructor(name, level, numberOfStudents, sportsTeams){
    super(name, level, numberOfStudents)
    this._sportsTeams = sportsTeams
  get sportsTeams(){
    return this. _sportsTeams

const lorraineHansbury = new Primary('Lorraine Hansbury', 'primary', 514, 'Students must be picked up by a parent, guardian, or a family member over the age of 13.');
School.pickSubstituteTeacher(['Jamal Crawford', 'Lou Williams', 'J. R. Smith', 'James Harden', 'Jason Terry', 'Manu Ginobli']);

const alSmith = new High('Al E. Smith', 'high', 415, ['Baseball', 'Basketball', 'Volleyball', 'Track and Field']);
1 Like

you should call the quickFacts method on the instance of your primary school (lorraineHansbury), not on the class itself.

the class instance (lorraineHansbury) set the instance variables through the constructor.

1 Like

Thx for the reply.
When i call with: “lorraineHansbury.quickFacts()” the problem is: “TypeError: lorraineHansbury.quickFacts is not a function”
I found the solution:
I remove from “static quickFacts()” the static method and it work, but why?
Ok i found.
The exercise say: " Methods : .quickFacts() and .pickSubstituteTeacher() (this is a static method)"
But only the last one is a static method.

1 Like