Geters and setters


Hi everyone!
I don’t understand one thing:

let person = {
  _name: 'Lu Xun',
  _age: 137,
set age(ageIn){
    if(typeof ageIn ==='number'){
      this._age = ageIn;
      return 'Invalid input'
  get age(){
    console.log('${name} is ${age} years old');
    return this._age;
person.age = 'Thirty-nine';
person.age = 39;

why ${name} and ${age} are inside a string?
the output is : ${name} is ${age} years old
instead of: Lu Xun is 39 years old
I still got it correct in the lesson but i don’t know why .


Hi @kati210
There should be backticks (`) instead of ’ in the age getter
I don’t know know why you got it correct.
There must be a problem in codecademy
Moderators know this better


es6 string interpolation (${}) which allows variables within a string, requires backticks, not apostrophes like you used

Sometimes, corner case slip through the cracks.


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