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
Ismael Ramirez
3,627 Pointswhat's wrong with my code so far? The 'list' doesn't appear.
var instock = [ 'apples', 'milk', 'cookies', 'cheese', 'bread', 'lettuce', 'carrot', 'broccoli', 'pizza', 'potato', 'galletas', 'onions', 'cucumber']; var search;
function print(message) { document.write( '<p>' + message + '</p>'); }
while (true) { search = prompt("Search for a product in our store. Type 'list' to show all of the products and 'quit' to exist"); if ( search === 'quit') { break; } else if (search === 'list') { print( inStock.join(', ') ); } }
1 Answer
Steven Parker
243,266 PointsJavaScript is a case-sensitive language, and your array is named "instock" (with lower-case "s") but referenced as "inStock" (with capital "S").
It's important that they match, and the "best practice" naming convention would be to use the capital "S" version.
Yacine Freifer
6,717 PointsYacine Freifer
6,717 Pointsdocument.write( '<p>' +"We have "+ inStock.join(', ') + '</p>'); }
You can loop through each item using a forloop within this while loop.