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

Kimberly Dolcin
Kimberly Dolcin
4,369 Points

There is no prompt or alert box that pops up, what is wrong with my code please?

// 1. Attach this file -- practice.js -- to the index.html file using a <script> tag

// 2. In this JavaScript file, add a prompt dialog to capture input from the user and store it in a variable

// 3. Add a second a prompt dialog to capture input from the user and store it in a second variable

// 4. Create a third variable and which combines an uppercase version values in the two other variables separated by a space. For example, if the first two variables contain "sally" and "forth", this third variable should contain the string value "SALLY FORTH"

// 5. Create a fourth variable to store a number. The number should be the total number of characters in the third variable.

// 6. Add an alert dialog box that says "The string '[insert value of third variable here]' is X number of characters long." For example, if the third variable contained the string "SALLY FORTH" then the alert dialog should says "The string 'SALLY FORTH' is 11 characters long."

var input = prompt("What is your First Name?"); var input2 = prompt("What is your Last Name?"); var uppercase = input.toUpperCase() + " "+ input.toUpperCase(); var totalnumbers = uppercase.length; alert("The string \"" + uppercase + "\" "is"+ totalnumbers + "number of characters long.");

1 Answer

Here is your code

var input = prompt("What is your First Name?"); var input2 = prompt("What is your Last Name?"); var uppercase = input.toUpperCase() + " "+ input.toUpperCase(); var totalnumbers = uppercase.length; alert("The string \"" + uppercase + "\" "is"+ totalnumbers + "number of characters long.");

Here is mine. Spot the difference(s)

var input = prompt("What is your First Name?"); 
var input2 = prompt("What is your Last Name?"); 
var uppercase = input.toUpperCase() + " " + input2.toUpperCase(); 
var totalnumbers = uppercase.length; 
alert("The string \"" + uppercase + " " + "is" + totalnumbers + "number of characters long.");

Aside: Make sure you understand when to use the escape character, "\". I'm having trouble providing a good explanation. I think this is when one learns they don't know as much as they thought or at least know it well enough to explain it :). Cheers!