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 trialDennis 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?
Dennis Kummerfeldt
6,541 PointsIan Cahn That was it, thank you!
2 Answers
Tyler Duke
4,344 PointsHey, 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
6,541 PointsThank you for that recommendation :)
Ian Cahn
7,245 PointsIan Cahn
7,245 PointsHey, arent you just missing a "(" in your toLowerCase method?
like .toLowerCase() ?