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 trialmichelle Jia
4,814 Pointsbreak 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
231,236 PointsA "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.