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

Is a space a character itself?

Just wondering, because the name in the video actually has 13 characters, and it says 14 due to the space that has been added. But is the space a character itself?

I want to know the length of the Full name without the space, right? So isn't the solution wrong in some way?

3 Answers

Space is a character so it will be included in the length

Jamie Reardon
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jamie Reardon
Treehouse Project Reviewer

You can either remove the space character from the string or use the trim method to remove it for you. That is a method out of the scope of the course but a quick google won't do any harm.

Yeah I solved it when I posted this question, I was just wondering if the solution is in some way wrong, due to the fact that, for example, my full name has 12 characters, not 13 :P Anyway thank you for your answer and your time!

Jamie Reardon
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jamie Reardon
Treehouse Project Reviewer

Well in Javascript, a whitespace is also considered a character just as letters are. So the solution is not wrong. Although the way it has been entailed could be misinterpreted easily. The length property will provide the length of the entire value.

In a later JavaScript course, you will see and understand the length property and its use cases much further.

I combat this issue with the following: var numChars = fullName.replace(/ /g,"").length; I noticed this "issue" as well, the difference in what humans expect the length to be versus the literal value a computer sees. Hope this helps you, and/or anyone else in this course.