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

Could this be a better solution based on what we've been taught?

const firstName = prompt("Tell us your first name:");
const lastName = prompt("Tell us your last name:");
const fullName = `${firstName.toUpperCase()} ${lastName.toUpperCase()}`
const number = firstName.length + lastName.length;
alert(`The string '${fullName}' is ${number} number of characters long.`);

This is what I've done before seeing the solution.

Why do I want to know If this is best.

First, I we want to count character shouldn't we count space out?

Second, won't it make sense to use template literal instead of adding up variables to get the full name?

Third, isn't it more simple to construct the alert message using template literal?

Cheers

1 Answer

Robert Manolis
STAFF
Robert Manolis
Treehouse Guest Teacher

Hey Pedro Oliveira, great questions. A space is a character, so those should be counted. And the difference between interpolated template literals and old school concatenated strings is really just a style choice. They both work equally well and accomplish the same thing. :thumbsup: