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

Dylan Bailey
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Dylan Bailey
Front End Web Development Techdegree Graduate 17,232 Points

.toLowerCase() on prompt?

Guil is showing multiple ways to return a user's search as lowercase. I added the method to my initial prompt() call and had no issues.

const search = prompt('Search for a product.').toLowerCase();

Is this a valid way of calling the method? Or would the following example be best practice?

const search = prompt('Search for a product.');
searchText = search.toLowerCase();

1 Answer

Steven Parker
Steven Parker
229,732 Points

The more compact first form would be fine unless there might be a reason to refer to the original response later in the code. In that case, the 2nd form would be preferable.