Getters and setters III. ${} does not work


#1

<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/learn-javascript-objects/lessons/objects/exercises/getters-setters-iii?action=lesson_resume&course_redirect=introduction-to-javascript

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
console.log does not print the correct values.It prints: ${this._name} is ${this._age} years old.
undefined

```

let person = {
_name: ‘Lu Xun’,
_age: 137,

set age(ageIn) {
if (typeof ageIn === ‘number’) {
this._age = ageIn;
}
else {
console.log(‘Invalid input’);
return ‘Invalid input’;
}
},

get age() {
console.log(’${this._name} is ${this._age} years old.’);
}

};

person.age = 39;
console.log(person.age);

<do not remove the three backticks above>

#2

Template strings must be enclosed in backticks

`This is a ${template} string.`

#3

Thanks for your help!


#4

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