Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialThomas Moore
Front End Web Development Techdegree Graduate 25,371 PointsTemplate literal not outputting its value in Workspaces. Have I made a typo?
For some reason when I run the code below in node in workspaces, I get something different logged to the console than in the video. Am I doing something wrong??
My console log:
- setter called: ${owner}
- Ashley
Instead of:
- setter called: Ashley
- Ashley
class Pet {
constructor(animal, age, breed, sound) {
this.animal = animal;
this.age = age;
this.breed = breed;
this.sound = sound;
}
get activity() {
const today = new Date();
const hour = today.getHours();
if (hour > 8 && hour <= 20) {
return 'playing';
} else {
return 'sleeping';
}
}
get owner() {
return this._owner;
}
set owner(owner) {
this._owner = owner;
console.log('setter called: ${owner}');
}
speak() {
console.log(this.sound);
}
}
const ernie = new Pet('dog', 1, 'pug', 'yip yip');
const millie = new Pet('dog', 5, 'spaniel', 'woof woof');
ernie.owner = 'Ashley';
console.log(ernie.owner);
1 Answer
KRIS NIKOLAISEN
54,971 PointsThis
console.log('setter called: ${owner}');
should be this (with back ticks not single quotes)
console.log(`setter called: ${owner}`);
Thomas Moore
Front End Web Development Techdegree Graduate 25,371 PointsThomas Moore
Front End Web Development Techdegree Graduate 25,371 PointsAh! Thanks Kris, can't believe I missed that as a template literal. Rookie mistake.