How do I resolve a TypeError in the School Catalogue Project?

I am working on the School Catalogue Project in the Classes module and have come to the end of the project but am stuck on a Type Error I don’t know how to resolve.

Project

Here is the error for reference:

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

TypeError: School.pickSubstituteTeacher is not a function
    at Object.<anonymous> 

What am I doing wrong here :confused:?

Hey Amy! How are you doing?
I may be able to help you, can you please share your code?

Thanks,

Here is where I created pickSubstituteTeachers under #7 in the School 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;
   }
   // 5
   set numberOfStudents(value) {
     this._numberOfStudents;
     if (value.isNaN()) {
       console.log('Invalid input: numberOfStudents must be set to a Number.');
     } else {
       this._numberOfStudents = value;
     }
    }     
   // 6
   quickFacts() {
     console.log(`${this.name} educates ${this.numberOfStudents} students at the ${this.level} school level.`);
   }
   // 7
   static pickSubstituteTeachers(substituteTeachers) {
     const randInt = Math.floor(Math.random() * substituteTeachers.length);
     return substituteTeachers[randInt];
    }
  }

And here is where I called pickSubstituteTeachers outside of the class:


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

There is an additional class below the School class but I don’t want to post too much 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; } // 5 set numberOfStudents(value) { this._numberOfStudents; if (value.isNaN()) { console.log('Invalid input: numberOfStudents must be set to a Number.'); } else { this._numberOfStudents = value; } } // 6 quickFacts() { console.log(`${this.name} educates ${this.numberOfStudents} students at the ${this.level} school level.`); } // 7 static pickSubstituteTeachers(substituteTeachers) { const randInt = Math.floor(Math.random() * substituteTeachers.length); return substituteTeachers[randInt]; } }; School.pickSubstituteTeachers(['Jamal Crawford', 'Lou Williams', 'J. R. Smith', 'James Harden', 'Jason Terry', 'Manu Ginobli'])

This works just fine for me :confused:

Arrgh! Haha you got a typo there! :stuck_out_tongue:
pickSubstituteTeacher instead of pickSubstituteTeachers

2 Likes

Oh my gosh! Goodness!

Thank you!

1 Like

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