School Catalogue - [Step 19 ] class SchoolCatalog and push() of undefined error


Hello, Apoliges if this has been covered before.
I’m learning JS and can’t seem to complete the optional step 19 of the above classes course.

I did the exact same as i did in the previous assignment related to building a Media Catalog, but this time I’m getting an error.
TypeError: Cannot read property ‘push’ of undefined


TypeError: Cannot read property 'push' of undefined
    at SchoolCatalog.addSchool (/home/ccuser/workspace/learn-javascript-classes-school-catalog/app.js:16:17)
    at Object.<anonymous> (/home/ccuser/workspace/learn-javascript-classes-school-catalog/app.js:93:22)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:427:7)
    at startup (bootstrap_node.js:151:9)
class SchoolCatalog { contructor(level) { this._level = level; this._schools = []; } get level() { return this._level; } get schools() { return this._schools; } addSchool(value) { this.schools.push(value); } } 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(value) { if (typeof value === "number") { this._numberOfStudents = value; } console.log("Invalid input: numberOfStudents must be set to a Number."); } quickFacts() { console.log( `$(this._name) educates $(this._numberOfStudents) students at the $(this._level) level.` ); } static pickSubstituteTeacher(substituteTeachers) { let randInt = Math.floor(Math.random() * substituteTeachers.length); return substituteTeachers[randInt]; } } class PrimarySchool extends School { constructor(name, numberOfStudents, pickupPolicy) { super(name, "primary", numberOfStudents); this._pickupPolicy = pickupPolicy; } get pickupPolify() { return this._pickupPolicy; } } class MiddleSchool extends School { constructor(name, numberOfStudents) { super(name, "middle", numberOfStudents); } } 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", ]); console.log(sub); const alSmith = new HighSchool("Al E. Smith", 415, [ "Baseball", "Basketball", "Volleyball", "Track and Field", ]); console.log(alSmith.sportsTeams); const primarySchoolCatalog = new SchoolCatalog("Primary Schools"); primarySchoolCatalog.addSchool(lorraineHansbury); const highSchoolCatalog = new SchoolCatalog("High Schools"); highSchoolCatalog.addSchool(alSmith);

I’m sure I’m missing something plainly obvious but I’ve been stuck on this for half a day.

just check the spelling of the constructor. Everything else ist fine.

1 Like

How embarrassing, clearly spelling is not my thing.

Thank you so, so much.

1 Like