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 trialDelicia Wharton
UX Design Techdegree Student 11,098 PointsIs 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
John D
7,237 PointsThe 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
8,481 Pointsi 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
1,783 PointsIf you run the code twice, you are basically redefining all the variables again. the const variable cannot be redefined again.
Simon Coates
8,481 PointsSimon Coates
8,481 PointsI'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.