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 JavaScript Basics Working with Strings Display the Value of a String on a Page

Is this valid code

const stringToShout = prompt("What do you want to shout?"); const shout = stringToShout.toUpperCase(); const shoutMessage = The message to shout is: ${shout}!! ;

console.log(shoutMessage);

I followed directly from the teacher, but when I hit "view" it doesn't do anything after I input something into the dialogue box. I got this message when i put it into the console on chrome:

VM57:1 Uncaught SyntaxError: Identifier 'shout' has already been declared

but I only declared the variable once and did not call it into the console, this is very irritating. Am I missing a typo?

2 Answers

The variable needs to have backticks wrapped around the message to concatenate it. Your variable's value in "shoutMessage" is missing the backticks needed to avoid that error message.

it should be

shoutMessage = `The message to shout is: ${shout}!!` ; 
Simon Coates
Simon Coates
8,377 Points

I've seen a couple instances recently where users posted the interpolation syntax but didn't use the 3 backticks to flag it as code. The backticks were missing in each case, so I'm assuming it's just an oddity.

Simon Coates
Simon Coates
8,377 Points

i ran it (as below) in my developer console:

const stringToShout = prompt("What do you want to shout?"); 
const shout = stringToShout.toUpperCase(); 
const shoutMessage = `The message to shout is: ${shout}!!` ;

console.log(shoutMessage);

it seemed to work. So your code is valid. But if I ran in the console twice, I'd get a similar error unless I refreshed the browser window.

Sreeraj PJ
Sreeraj PJ
1,783 Points

If you run the code twice, you are basically redefining all the variables again. the const variable cannot be redefined again.