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 The Solution

The alert doesn't work.

The alert in my code doesn't work. Everything works fine until I add the alert - then nothing works and the console says that it's a SyntaxError with missing ) on that line. It was first identical with Dave's solution in the video and didn't work. After reading the other questions and answers here I added a " after "is" but it still doesn't work. Would be glad for some help!

let firstName = prompt("What is your first name?", "Write your first name here");

let familyName = prompt("What is your family name?", "Write your family name here");

let completeName = firstName.toUpperCase() + ' ' + familyName.toUpperCase();

let characterCount = completeName.length;

alert("The String \"" + completeName + "\" is " + " characterCount + " characters long.");

Rebecca Meyer
Rebecca Meyer
7,962 Points

alert(The String ${completeName} is ${characterCount} characters long.);

Hi Ingrid. You forgot to add the backticks here ``

1 Answer

Hey Ingrid Pettersson,

The reason for that syntax error is because your last ) is being treated as if it were part of a string (and not the closing parenthesis for the alert function). I think you may have gotten a bit confused with all of the double quotes and concatenating in that alert function.

My advice would be to re-start the entire string with single quotes, that way you wonโ€™t have to escape your double quotes. If you do this, I think youโ€™ll see where youโ€™ve opened a string without ending it.

I tried that but still couldn't find the error. Now I learned that the new JavaScript syntax for this alert would be as follows:

alert(The String ${completeName} is ${characterCount} characters long.);

When I do this it works! Would you say that this is the same function but with newer JS syntax, or is there a difference between the functions?

Itโ€™s a newer JS syntax. Itโ€™s called a template string.

Thank you Brandon!