School Catalogue

Having an issue with this static function in the School Catalogue project. The function takes an array, and is supposed to randomly pick between them and return it. Here’s my code:

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

Here’s the error:

/home/ccuser/workspace/learn-javascript-classes-school-catalog/app.js:29
    num = Math.floor((Math.Random() * substituteTeachers[length -1]));
                           ^

TypeError: Math.Random is not a function
    at Function.pickSubstituteTeacher 

Here’s my full project:

Summary

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(newNumber) {

if (!isNaN(newNumber)) {

  this._numberOfStudents = newNumber;

} 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 num = 0;


num = Math.floor(Math.Random() * substituteTeachers[length -1]);

return substituteTeachers[num];

}

}

class Primary extends School {

constructor(name, numberOfStudents, pickupPolicy) {

super(name, "Primary", numberOfStudents);

this._pickupPolicy = pickupPolicy;

}

get pickupPolicy() {

return this._pickupPolicy;

}

}

class Middle extends School {

constructor(name, level, numberOfStudents) {

super(name, level, numberOfStudents);

}

}

class High extends School {

constructor(name, numberOfStudents, sportsTeams){

super(name, "High", numberOfStudents);

this._sportsTeams = sportsTeams;

}

get sportsTeams() {

return this._sportsTeams;

}

}

const lorraineHansbury = new Primary(“Lorraine Hansbury”, 514, “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’]);

The Math object has function Math.random(), but not Math.Random(). Try changing the capitalization and see if that helps.

2 Likes

oh, my thank you, that did indeed do the trick. Thanks!