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 trialHarsh Khandelwal
5,539 PointsWhy is the break keyword illegal statement error when I try to write break in the if condition of the forEach code?
teachers.forEach(teacher => {
console.log(teacher.name);
if (teacher.name === 'Nick') {
console.log(teacher.rating);
break;
}
});
break;
^^^^^
SyntaxError: Illegal break statement
Mark Casavantes
Courses Plus Student 13,401 PointsHello Harsh,
It would be helpful to print out all your code when you have a question.
From what I can see I would try switching => to >=.
http://www.w3schools.com/js/js_comparisons.asp
I hope this is helpful.
Jason Anello
Courses Plus Student 94,610 Pointsformatted code
christopher abramson
22,741 Pointschristopher abramson
22,741 PointsI don't believe you can use forEach like that. If you want to achieve the same result with a break you could use a
Switch
or if you want to do it without a break you could use a
While loop.