School Catalogue questions

When I try to run this it says “name is undefined.” I don’t understand why

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 } quickFacts() { console.log(`${name} educates ${numberOfStudents} students at the ${level} school level.`) } static pickSubstituteTeacher(substituteTeachers) { const randNum = Math.floor(Math.random() * substituteTeachers.length) } set numberOfStudents(newNumberOfStudents) { if (newNumberOfStudents.isNaN()) { console.log('Invalid input: numberOfStudents must be set to a Number.') } } } 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()

I think you’re missing the this so that those variables are the properties of the object.
On that line,
name should be or maybe this._name;
numberOfStudents should be this.numberOfStudents ;
level should be this.level

Yeah, I figured that out. Thx

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