Hi, I’ve just completed the School Catalogue project in the Classes topic of JavaScript.
I’m getting correct output when i console log things in my code, but each output has an “undefined” tacked on the end.
Could someone tell me what I am missing, I cant find it myself!
Here is my code:
[code]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(${this._name} educates ${this._numberOfStudents} students at the ${this._level} school level.
)
}
static pickSubstituteTeacher(substituteTeachers) {
const rand = Math.floor(Math.random()*(substituteTeachers.length - 1));
return substituteTeachers[rand];
}
set numberOfStudents(numberOfStudents) {
if (typeof numberOfStudents === “number”) {
this._numberOfStudents = numberOfStudents;
} else {
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() {
console.log(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.’);
console.log(lorraineHansbury.quickFacts());
console.log(School.pickSubstituteTeacher([‘Jamal Crawford’, ‘Lou Williams’, ‘J. R. Smith’, ‘James Harden’, ‘Jason Terry’, ‘Manu Ginobli’]));
const alSmith = new HighSchool(‘Al E. Smith’,415,[‘Baseball’,‘Basketball’,‘Volleyball’,‘Track and Field’]);
console.log(alSmith.sportsTeams);[/code]
And here is the output to my 3x console.logs:
[color=blue]Lorraine Hansbury educates 514 students at the primary school level.
undefined
Lou Williams
[ ‘Baseball’, ‘Basketball’, ‘Volleyball’, ‘Track and Field’ ]
undefined[/color]
Thanks!