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

Dennis Kummerfeldt
Dennis Kummerfeldt
6,541 Points

.toLowerCase not working?

I wanted to change the code of this video a bit in order to be able to search for "BROCCOLI" instead of just "broccoli" and still get a true from the includes method.

The Code, that checks the array: if (inStock.includes (search.toLowerCase)) { message = Yes, we have <strong>${search}</strong>!; } else { message = Sorry, we do not have <strong>${search}</strong>.; }

This gives me a true if I search for "broccoli" however I get a false when I search for "Broccoli"

The Code with the .toLowerCase method:

if (inStock.includes (search.toLowerCase)) { message = Yes, we have <strong>${search}</strong>!; } else { message = Sorry, we do not have <strong>${search}</strong>.; }

After I did that I always got the "Sorry" message.

Can someone help me? What am I doing wrong here?

Hey, arent you just missing a "(" in your toLowerCase method?

like .toLowerCase() ?

2 Answers

Hey, just for future reference, this is one of my favorite tools if I suspect something isn't working when it should be

Validators can be pretty handy if you think your IDE isn't logging everything, or if you need extra insight into what's happening. Most of the popular languages have validators online.

Dennis Kummerfeldt
Dennis Kummerfeldt
6,541 Points

Thank you for that recommendation :)