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

break statement not work in my program, check error in the console, saying illegal break statement, please kindly advise

function store (){ search = prompt('search a product in our store, or you can input list to show all the products, or you can input quit to exit'); search= search.toLowCase(); if (search === 'quit'){ break; }else if (search === 'list'){ print(inStock.join('; ')); }else { if (inStock.indexOf(search)>-1){ print('Yes, we have the ' + search + ' in our store.' ); }else { print('Sorry, we don't have the ' + search + '.'); } } }

1 Answer

Steven Parker
Steven Parker
216,148 Points

A "break" is used to end a loop, and is only allowed inside a loop. Did you intend to create a loop around this code?

If you want to end a function, use "return" instead.