JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Useful Array Methods

Filip Diarra
Filip Diarra
6,647 Points

Javascript Issue..Please help.

Please let me know what is wrong with this code. I keep getting unexpected end of input error, but I think I'm following the teacher pretty much to the tee.

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 ) { var search = prompt("Search for a product in our store. Type 'list' to show all products. Type 'quit' to exit."); if (search === 'quit') { break; }

Thanks!

2 Answers

Benjamin Barslev Nielsen
Benjamin Barslev Nielsen
18,955 Points

This is your while loop:

while ( true ) { 
    var search = prompt("Search for a product in our store. Type 'list' to show all products. Type 'quit' to exit."); 
    if (search === 'quit') { 
        break; 
    }

You have forgotten a } to close the body of your loop.

Filip Diarra
Filip Diarra
6,647 Points

Also, this doesn't work whether I use "var" in the body of the function or not.

Filip Diarra , You forget to close while condition on line 31.