I noticed in this project that we place a setter in the School parent class, but it doesn’t seem as useful as I would have expected. It’s supposed to log an error message if we attempt to set the number of students to anything but a number, but it doesn’t catch such an error if it occurs when declaring a new object. For example:
const lorraineHansbury = new PrimarySchool('Lorraine Hansbury', 'test', 'Students must be picked up by a parent, guardian, or a family member over the age of 13.') lorraineHansbury.quickFacts() // logs 'Lorraine Hansbury educates test students at the primary school level.'
Notice that ‘test’ is not a number, yet we don’t get an error message. The only time we actually get an error is if we try to change that property specifically, via the defined setter:
lorraineHansbury.numberOfStudents = 'test' // logs the error message
I guess my main question is, is there some way to set up a conditional with classes that will only accept certain data when we’re declaring the new object? For instance, like I’d expected in the first example?