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

Ben Os
Ben Os
20,008 Points

Chalkers won't be printed after node app.js

In this video I used a workspace with the following code:

function printMessage(userName, badgeCount, points) {
    let message = '${userName} has ${badgeCount} total badge(s) and ${points} points in Javascript.';
    console.log(message);
}

printMessage('chalkers', 100, 2000000);

After adding the code and saving app.js I went to the console (in the workspace) and executed app.js but got

${userName} has ${badgeCount} total badge(s) and ${points} points in Javascript.

This is not a plausible respone, why did I get it?

1 Answer

Steven Parker
Steven Parker
231,269 Points

When you use template interpolation, your template string must be enclosed in accents ("back-ticks") instead of apostrophes ("single quotes") or double quotes. Otherwise the placeholders are treated as just part of the string.

    let message = `${userName} has ${badgeCount} total badge(s) and ${points} points in Javascript.`;
Ben Os
Ben Os
20,008 Points

Oh, I confused the backticks with tildes, so I thought I should use "forwardTicks" (single quotes). Thank you Steven.