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 Working with 'for' Loops Exit a Loop

The loop ends but still alert message

The loop stops when it reaches the break statement, but the alert message is still gonna run after the loop? Isn't it

2 Answers

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,722 Points

You're perceptive!

The program is correct for a testing piece to learn the flow of for loops, if statements, and break. But as you surmise, there are other things that can improve it.

Good luck with your JavaScript journey-- it is a very good language to get on your toolbelt.

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,722 Points

You are correct! The alert is posted after the loop.

So technically the program is wrong?