Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Getting Started With ES2015 Using Template Literals String Interpolation

I can't get interpolation to work. I typed it out like in the video, but when I refreshed the page, nothing appeared.

nothing appears in the interpolation slot in the template literals tab even though I have typed it out exactly like in the video. what's going on?

What does the console say?

Michael Hulet
Michael Hulet
47,841 Points

Can you paste the code you're having trouble with here? It'd help us a lot if we could see your code and try it ourselves

3 Answers

You are missing a few backticks

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

function love(thing) { return `I love ${thing}` ; } //after ${thing} here

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

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

here it is.

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;

I tried to make it exactly like the teacher showed in the video, and I'm pretty sure it is exactly the same. But for some reason it didn't work when I viewed it. Thank you for responding.

Thanks. I hadn't noticed that.