Project: School catalogue || Help needed


#1

Hi there,

I could use some advice with regard to below code. The output I get is stated below. Can you guys help me move in the right direction so I can solve this and continue the assignment?

Output:
Lorraine Hansbury educates undefined students at the primary school level
undefined

//parent class
class School{
    constructor(name, level, numberOfStudents){
        this._name = name;
        this._level = ['primary', 'middle', 'high'];
        this._numberOfStudents = numberOfStudents;
    }

    get name() {
        return this._name;
    }

    get level() {
        return this._level;

    }

    get numberOfStudents() {
        return this._numberOfStudents;
    }

    set numberOfStudents(newNumberOfStudents){
        if (typeof newNumberOfStudents === 'number') { //controleert of de property een getal is;
            this._numberOfStudents = newNumberOfStudents; //vervangt oude number of students met nieuwe number of students;
        } else {
            console.log('Invalid input: The number of students must be set to a number');
        }
    }

    //loggen van de uitkomst
    quickFacts(name, numberOfStudents, level) {
        console.log(`${this._name} educates ${this._numberOfStudents} students at the ${this._level} school level`);
    }

    static pickSubstituteTeacher(substituteTeachers) {
        var randomTeacher = Math.floor(substituteTeachers.length * Math.random() - 1);
        return substitueTeachers[randomTeacher];
    }

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

    }

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


//child class: middle
class MiddleSchool extends School{
    constructor(name, numberOfStudents){
        super(name);
        this._level = 'middle';
    }
}


//child class: high
class HighSchool extends School{
    constructor(name, numberOfStudents){
        super(name);
        this._sportsTeams = [];
        this._level = 'high'
    }
}

var lorraineHansbury = new PrimarySchool('Lorraine Hansbury', 514, 'Students must be picked up by a parent, guardian, or a famlily member over the age of 13.')

console.log(lorraineHansbury.quickFacts());

#2

here:

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

why does your method have 3 parameters? we can just access the properties through self, otherwise we would need to supply the arguments again when we call the method (which violated DRY)

also, in a method you should use this.name, the underscore is only a naming convention to indicate the property uses getters and maybe setters. so this._name (the underscore) should only be used in the constructor, and getter and setter methods