OBJECTS Getters and Setters I


My code will not pass the second test. I can’t seem to see why.
Here is my code:

let person = {
  _name: 'Lu Xun',
  _age: 137,
set age(newAge){
  if (typeof newAge === 'number') {
    this._age = newAge;
  } else  {
   return "Invalid input"

and a link to the lesson:

Getters and Setters 12/15


you need return 'Invalid input', the string needs to be enclosed in apostrophes.



That makes it pass the test however, aren’t quotes proper code in a return? Is this just something that the test is looking for that does not effect the code?


In JavaScript both single and double quotes resolve to single quotes internally. However, if the author wrote the SCT with only single quotes, and did not write for double quotes the lesson will not pass. This is an oversight by the author, if that is the case.

Technically, in ES6 we have template strings that use backticks…

console.log(`Invalid input`)

which can also be used in place of quotes. There are not very many places we cannot use ticks, and some authors have stopped using single and double quotes altogether.