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

unexpected token on line 9

I am trying to follow along in workspaces and i am trying to follow the syntax but my code does not run an i would like to understand why

I keep getting unexpected token on line 9

here is 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 the store. Type 'List' to see a full list. Type 'quit' to exit.) }; if (search.toLowerCase() ==='quit'){break;}

2 Answers

Colin Bell
Colin Bell
29,679 Points

You forgot to close your double quote in your prompt.

You're also going to want to move that if statement inside the while statement, otherwise you're going to get an 'illegal break' console error.

Also, just curious, but why are you concatenating blanks to the beginning and end of the message?

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('' + message + '');
}

while (true) {
  search = prompt("Search for a product in the store. Type 'List' to see a full list. Type 'quit' to exit.")
  if (search.toLowerCase() === 'quit') {
    break;
  }
};

Thanks so much! The concatenation is the result of copy pasting the code from workspaces they were originally opening and closing paragraph tags.