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

Jeffrey Lawton
Jeffrey Lawton
6,284 Points

Name variable is not being used (JavaScript Everywhere video)

Hi everyone.

I was doing the code-along project in the video, and when I run my code in the JS console, the name variable is not used and just shows up as ${name} instead. Am I doing something wrong or is there something that's changed about the syntax?

Code here:

var name = "your name"; alert('Hi, ${name}. Want to see something cool?'); document.querySelector('html').innerHTML = '<h1>Welcome to ${name}\'s site!</h1><img src="https://media.giphy.com/media/JIX9t2j0ZTN9S/giphy.gif">';

Also, it looks like this gif is not usable anymore due to the error I get:

Refused to load the image 'https://media.giphy.com/media/JIX9t2j0ZTN9S/giphy.gif' because it violates the following Content Security Policy directive: "img-src 'self' *.githubusercontent.com *.googleusercontent.com lux.speedcurve.com mdn.mozillademos.org media.prod.mdn.mozit.cloud media.stage.mdn.mozit.cloud interactive-examples.mdn.mozilla.net wikipedia.org www.google-analytics.com www.gstatic.com".

2 Answers

Rohald van Merode
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Rohald van Merode
Treehouse Staff

Hi Jeffrey Lawton 👋

It's hard to tell without seeing your code but I think there might be an issue with the code you've written. Could you make sure if you're using backticks ` in both the alert and the innerHTML method on line 3-6 instead of regular single quotes '.

If that doesn't work please share your code and I'd be happy to have another look 🙂

The problem is that you have used single quotation mark instead of backtick. Example of backtick is ``. We wrap a string with backtick in template literal instead of wrapping it with a double or single quote.

Jeffrey Lawton
Jeffrey Lawton
6,284 Points

Thank you! I thought they looked funny but I kept writing it off as different font or something. lol