Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


Brandon Davis
Brandon Davis
Full Stack JavaScript Techdegree Student 7,405 Points

Slightly Different Method, Same Result. Curious if my method is a bad habit...

Dave uses a series of concatenation to display his strings differently then mine. When completing the task, I decided to use template literals as I find them easier to work with. I got the same result but would love feedback to see if I'm doing what's considered "best practice". (This is my first time posting a questions so apologies if If I do this wrong!)

// 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
const firstName= prompt('What is your first name?');
// 3. Add a second a prompt dialog to capture input from the user and store it in a second variable
const lastName = prompt('What is your last name?');
// 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"
const fullName = `${firstName.toUpperCase()} ${lastName.toUpperCase()}`;
// 5. Create a fourth variable to store a number. The number should be the total number of characters in the third variable. 
const fullNameLength = fullName.length;
console.log (fullNameLength);
// 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."
alert(`The string ${fullName} is ${fullNameLength} characters long!`);

Any feedback at all would be greatly appreciated! Have a great day!

1 Answer

Steven Parker
Steven Parker
212,140 Points

There's rarely only one way to accomplish a programming task. Your use of template literals takes advantage of a more advanced technique and allows the code to be a bit more compact than the basic method. Good job! :+1: