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 trialKimberly Kohel-Hayes
2,896 PointsHere's my code, it doesn't work...
let firstName = prompt("What's your first name?");
let lastName = prompt("What's your last name?");
let fullName = ${"firstName"}
+ +
${"lastName"}
let upperCaseName = fullName.toUpperCase()
let fullNameLength = upperCaseName.length()
alert(The string
${upperCaseName}is
${upperCaseName.length}number of characters long.
)
2 Answers
Ryan Groom
18,674 PointsHey Kimberly Kohel-Hayes , so first of all in the third line you actually have to invoke the toUpperCase function with parentheses like so:
let fullName = (firstName + " " + lastName).toUpperCase();
In your fourth line you'll realize that the "upperCaseName" variable doesn't exist anymore after you refactored your code so you cannot pull the length from a variable that doesn't exist. Instead you will want to try something like this:
let fullNameLength = fullName.length;
So your final code should look like the following:
let firstName = prompt("What's your first name?");
let lastName = prompt("What's your last name?");
let fullName = (firstName + " " + lastName).toUpperCase();
let fullNameLength = fullName.length;
alert("The string "+"fullName" +" is " + fullNameLength + " number of characters long.");
Kimberly Kohel-Hayes
2,896 PointsKimberly Kohel-Hayes
2,896 PointsUpdate: I removed the template literals and simplified my code...
let firstName = prompt("What's your first name?");
let lastName = prompt("What's your last name?");
let fullName = (firstName + " " + lastName).toUpperCase;
let fullNameLength = upperCaseName.length;
alert("The string "+"fullName" +" is " + fullNameLength + " number of characters long.");