0

The goal is to pass an array of strings (Substitute teacher names) to the 'pickSubstituteTeacher' method and return one random teacher. I cannot figure out how to send an array of strings to the object method and return the random value.

class School {
  constructor(name, level, numberOfStudents) {
    this._name = name;
    this._level = level;
    this._numberOfStudents = numberOfStudents;
  }

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

const school1 = new School('school1', 'two', 233);


let randomTeacher = School.pickSubstituteTeacher['teacher1','teacher2','teacher3'];

console.log(randomTeacher);
4
  • 3
    well... i mean, an array looks like this: ['a','b','c']. Commented Oct 22, 2018 at 20:25
  • 3
    sorta related - you've made pickSubstitudeTeacher a static method, so you should be calling it with School.pickSubstituteTeacher -- or did you mean to not make it static? Commented Oct 22, 2018 at 20:27
  • I know, but even with square brackets it won't work. Commented Oct 22, 2018 at 20:27
  • @chazsolo you're right. I should be using School.pickSubstituteTeacher. But I still don't know how to pass it an array and return the randomly generated value. Commented Oct 22, 2018 at 20:28

2 Answers 2

1

You have to put parentheses around the array to indicate that the array is the argument to the method.

let randomTeacher = School.pickSubstituteTeacher(['teacher1','teacher2','teacher3']);
Sign up to request clarification or add additional context in comments.

1 Comment

Case closed. Thank you very much!
1

You are sooo close...

Go with this: let randomTeacher = School.pickSubstituteTeacher(['teacher1', 'teacher2', 'teacher3']);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.