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 trialEsther AlQaisi
2,311 PointsHere's my code (I converted the search variable toLowerCase)
I'm surprised Guil didn't do this since he's done it before in previous videos! I feel smarter than the teacher... lol! (let me have my moment) I tried Guil's code and input "Pizza" (with capital P) into the prompt box, and it returned "Sorry, we don't currently have Pizza." So I thought to convert the search variable toLowerCase so it would always match, no matter the case of the letters. Here's my code:
const inStock = ['pizza', 'cookies', 'eggs', 'apples', 'milk', 'cheese', 'bread', 'lettuce', 'carrots', 'broccoli', 'potatoes', 'crackers', 'onions', 'tofu', 'limes', 'cucumbers'];
const search = prompt('Search for a product.'); let message;
if ( inStock.includes( search.toLowerCase() ) ) {
message = Yes, we have <strong>${search.toLowerCase()}</strong>.
;
} else {
message = Sorry, we don't currently have <strong>${search.toLowerCase()}</strong>.
;
}
document.querySelector('main').innerHTML = <p>${message}</p>
;
2 Answers
Laura Dangler
3,301 PointsChecked out your code Good Job looks Great!
Steven Parker
231,248 PointsThere will often be opportunities to make the exercise code more elegant, as the examples are always focused on a particular point and not intended to be comprehensive solutions.
Making the search case-insensitive is a very practical enhancement, good thinking!
But don't do this on the challenges, the automation is very picky about what it expects and anything extra can confuse it.