School Catalog Project

Project Description Link

Having an issue that I can’t seem to debug with this project.

Whenever I try to call the pickSubstituteTeacher, I get an error stating that it is not a function.

If I remove static from the initial definition, it works, but I haven’t followed the project instructions. Format appears to match documentation, but obviously, I’ve missed something, or the program would work.

Also. I don’t understand why the bottom line is returning the number of items in the array along with the array.

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

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

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

class Primary extends School {
    constructor(name, level, numberOfStudents) {
        super(name, level, numberOfStudents, pickSubstituteTeacher);
        this._pickUpPolicy = '';
    }

    get pickupPolicy() {
        return this._pickUpPolicy;
    }

    set pickupPolicy(policy) {
        this._pickUpPolicy = policy;
    }
}

class Middle extends School {
    constructor(name, level, numberOfStudents) {
        super(name, 'middle', numberOfStudents, pickSubstituteTeacher);
    }
}

class High extends School {
    constructor(name, level, numberOfStudents) {
        super(name, 'high', numberOfStudents);
        this._sportsTeams = [''];
    }

    get sportsTeams() {
        return this._sportsTeams;
    }

    set sportsTeams(team) {
        this._sportsTeams.push(team);
    }
}

const lorraineHansbury = new Primary('Lorraine Hansbury', 'primary', 514);

lorraineHansbury.pickupPolicy = 'Students must be picked up by a parent, guardian, or a family member over the age of 13.';

lorraineHansbury.quickfacts();

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

const alSmith = new High('Al E. Smith', 'high', 415);

alSmith.sportsTeams = ['Baseball', 'Basketball', 'Volleyball', 'Track and Field'];

alSmith.sportsTeams.forEach(team => console.log(`Team: ${team}`));

thanks in advance.

the first error I get occurs on this line:

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

and the error is:

SyntaxError: Unexpected token )

which makes sense, the ) at the very end of that line, does not match anything. You seem to have one closing parenthesis too many

the next (actually interesting error) occurs here:

        super(name, level, numberOfStudents, pickSubstituteTeacher);

in the constructor of Primary. What is pickSubstituteTeacher doing here? pickSubstituteTeacher is not a property, its a method. Methods are inherited by child classes.

1 Like

oops, my bad, that was just me checking if i misunderstood, and i forgot to delete it.

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

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

    static pickSubstituteTeacher(substituteTeachers) {
        let myIndex = Math.floor(Math.random() * substituteTeachers.length - 1);
        return substituteTeachers[myIndex];
        console.log(substituteTeachers[myIndex]);
    }
}

class Primary extends School {
    constructor(name, level, numberOfStudents) {
        super(name, level, numberOfStudents, pickSubstituteTeacher);
        this._pickUpPolicy = '';
    }

    get pickupPolicy() {
        return this._pickUpPolicy;
    }

    set pickupPolicy(policy) {
        this._pickUpPolicy = policy;
    }
}

class Middle extends School {
    constructor(name, level, numberOfStudents) {
        super(name, 'middle', numberOfStudents, pickSubstituteTeacher);
    }
}

class High extends School {
    constructor(name, level, numberOfStudents) {
        super(name, 'high', numberOfStudents);
        this._sportsTeams = [''];
    }

    get sportsTeams() {
        return this._sportsTeams;
    }

    set sportsTeams(team) {
        this._sportsTeams.push(team);
    }
}

const lorraineHansbury = new Primary('Lorraine Hansbury', 'primary', 514);

lorraineHansbury.pickupPolicy = 'Students must be picked up by a parent, guardian, or a family member over the age of 13.';

lorraineHansbury.quickfacts();

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

const alSmith = new High('Al E. Smith', 'high', 415);

alSmith.sportsTeams = ['Baseball', 'Basketball', 'Volleyball', 'Track and Field'];

console.log(alSmith.sportsTeams);

still getting the same error I get anytime the method is declared as static. (Error: pickSubstituteTeacher is not a function)

otherwise still curious about how to return the sports teams array without the number first too

here:

    constructor(name, level, numberOfStudents) {
        super(name, level, numberOfStudents, pickSubstituteTeacher);
        this._pickUpPolicy = '';
    }

in the constructor of Primary, you still provide pickSubstituteTeacher as argument for super. But this variable does not exists. Same applies for Middle class constructor

what do you mean? Could you show me the output you get vs the output you desire?

I’m getting “Team:” on one line, followed afterwards by a second line that reads “Team: Baseball, Basketball etc”

My goal was to have it format as one line of output, and i missed the letter s when i wanted it to read Teams: …

what you tell me here does not match the code you last posted

you could use the getter for that.

1 Like