Getters and Setters I


#1

Hello

I´m getting the error messages for my code, and i can´t seem to find out what am i doing wrong…can someone give me a hint, please?

Here´s my code:

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

error:

/home/ccuser/workspace/learn-javascript-objects-getters-setters/main.js:11
};
^
SyntaxError: Unexpected token ;
at createScript (vm.js:53:10)
at Object.runInThisContext (vm.js:95:10)
at Module._compile (module.js:543:28)
at Object.Module._extensions…js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)


#2

the { of person object doesn’t have a matching closing curly bracket


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.