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

Extra character counted in completeName.length

This is in reference to https://teamtreehouse.com/library/the-solution-4... Since the variable completeName has an empty string with a space in it, it counts that as a character. So when you run the final program it adds an extra character to the final count of your full name. How can you go about subtracting the additional character count created by the space in the empty string, but still having a space between your first and last name?

1 Answer

Depends on what you are using it for. In some cases counting the space as a character is important. But you could always do this:

var characterCount = firstName.length + lastName.length;

or

var characterCount = completeName.length - 1;