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 trial

JavaScript Getting Started With ES2015 Using Template Literals String Interpolation

Simon Sporrong
Simon Sporrong
35,097 Points

Can't get the interpolation to work

Hi!

I'm trying to complete this step but can't get the interpolation to work.

function like(thing) {
  return 'I like ${thing}';
}

function love(thing) {
  return 'I love ${thing}';
}

const sentence = `<p>${like('apples')}, but ${love('oranges')}.</p>`;

document.querySelector('.interpolation').innerHTML = sentence;

What am i doing wrong? I am using google chrome as a browser. The browser will just print "I like ${thing} but I love ${thing}. Please help :)

2 Answers

You have to use backtick as well in your like and love function. When you use the single quote, you literally returning a I like ${thing} string.

function like(thing) {
  return `I like ${thing}`;
}

function love(thing) {
  return `I love ${thing}`;
}
Simon Sporrong
Simon Sporrong
35,097 Points

Yeah, i figured that out at last. Thank you for helping, Samuel :) I'm the dumbest boy in school.

Steve Mustanski
Steve Mustanski
15,093 Points

Everyone makes mistakes like that when learning.