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

Weronika Marciniak
Weronika Marciniak
2,140 Points

Why is nothing other than 'Search the Store' showing up in my document.write after I quit the prompt.

I copied exactly how the video was showing the example however after I ran the webpage and put my answers in the prompt I got nothing to show up on the page other than Search the Store. I rewrote the code two times in case of a spelling mistake but still nothing. Don't know what the problem could be?

My code:

var inStock = [ 'apples', 'eggs', 'milk', 'cookies', 'cheese', 'bread', 'lettuce', 'carrot', 'broccoli', 'pizza', 'potato', 'crackers', 'onion', 'tofu', 'frozen dinner', '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  the produce and 'quit' to exit");
  if ( search === 'quit' ) {
  break;
  }
}

[MOD: added ```JavaScript formatting -cf]

1 Answer

Steven Parker
Steven Parker
231,275 Points

It looks like there is a bit of work yet to do to make this a functional program. The code here is only the part that asks the question. All of the parts that respond to replies other than "quit" still need to be added yet.

Continue with the course, I'm sure the other parts will be added next.