School Catalogue Project


#1

Hi there,
In the Class course, it specifies that the Static Method created inside the parent class, cannot be accessed inside the child class. If I am creating a child from the parent class, how do I get to access the static method? This is not really clear inside the course materials.

Inside the School Catalogue project, it states that I need to create the Static method inside the parent class to access the .quickFacts(), however, started to create an instance of an objects that follow the Child of the Child of the Parent Class School. Both of these cannot access the static method inside the parent class.

I have included my source code below, I am unable to go past point 15.

Can you please help me here?
Thanks,
Baraa

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 (newNumberOfStudents) {
        if (newNumberOfStudents === number) {
            this._numberOfStudents = newNumberOfStudents;
        } else {
            console.log('Invalid input: numberOfStudents must be set to a Number.');
        }
        
    }

    static quickFacts () {
        // console.log('this is a static');
        
        console.log(`${this._name} educates ${this._numberOfStudents} students, typically between the ages of ${this._level}.`);
    }

    static pickSubstituteTeacher (substitureTeachers) {
        
        let substitureTeachersIndex =  Math.floor(Math.random() * substitureTeachers.length - 1);
        return substitureTeachers[substitureTeachersIndex];
    }


}

class PrimarySchool extends School{
    constructor(name, numberOfStudents, pickPolicy) {
        super(name);
        this._numberOfStudents = numberOfStudents;
        this._pickPolicy = pickPolicy;
        this._level='primary';
    }
}

class MiddleSchool extends School{
    constructor() {
        
    }
}

class HighSchool extends School{
    constructor(name, numberOfStudents,sportsTeams) {
        super(name);
        this._numberOfStudents = numberOfStudents;
        this._level = 'high';
        this._sportsTeams = sportsTeams;
    }
}



const mySchool = new School('mySchool','primary',100);
const myNewSchool = new PrimarySchool('baraa',10,'policy');

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.')

// console.log(myNewSchool);
// console.log(myNewSchool.numberOfStudents);
// console.log(lorraineHansbury.quickFacts());
console.log(School.quickFacts());
School.pickSubstituteTeacher(['Jamal Crawford', 'Lou Williams', 'J. R. Smith', 'James Harden', 'Jason Terry', 'Manu Ginobli']);
// console.log(PrimarySchool.lorraineHansbury.quickFacts());

#2

From Mozilla Devs: static, you can read:

Static method calls are made directly on the class and are not callable on instances of the class. Static methods are often used to create utility functions.

So I don’t think you will call the static method on a child element because it belong only to the parent class.