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!
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
Kim B4,941 Points
How to trim a user's input?
I'm sure this will be covered later, but it came to mind now. In this video, we see the necessity of adding a space in a concatenated string to make our final message legible. However, what about if a user erroneously adds a space at the end of their name, for example? Is there a trim function (er, command... method?) we can apply to our
prompt() method to account for that?
Steven Parker227,126 Points
Strings do in fact have a method named "trim" that will remove extra spaces from both the beginning and end.
let sloppy = " sample "; let neaten = sloppy.trim(); // will be "sample" (no spaces)