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 JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Useful Array Methods

Samantha Atkinson
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Samantha Atkinson
Front End Web Development Techdegree Graduate 40,307 Points

Using uppercase for the first letter of each item in an Array

I changed all the first letters of all the items in my array to Upper case and when I tested the program, the response kept being " not in stock" (final else statement) even though I input items that were definitely in the array. When I changed all the array items to all lower case it worked.

Could someone tell me why I couldn't use Uppercase for the first letter of every array item, please?

2 Answers

If you followed the instructions in the video you included the line

search = search.toLowerCase();

This transforms the stored answer from the prompt into all lowercase. You are then checking the lowercase prompt answer against your Capitalized array item using indexOf().

"indexOf() compares searchElement to elements of the Array using strict equality (the same method used by the === or triple-equals operator)."

Which will return false if their is a difference in capitalization.