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 trialIngrid Pettersson
9,916 PointsThe 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.");
1 Answer
Brandon White
Full Stack JavaScript Techdegree Graduate 35,771 PointsHey 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.
Ingrid Pettersson
9,916 PointsI 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?
Brandon White
Full Stack JavaScript Techdegree Graduate 35,771 PointsIt’s a newer JS syntax. It’s called a template string.
Ingrid Pettersson
9,916 PointsThank you Brandon!
Rebecca Meyer
7,962 PointsRebecca Meyer
7,962 Pointsalert(The String ${completeName} is ${characterCount} characters long.);
Hi Ingrid. You forgot to add the backticks here ``