Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.