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

Just grumbling: Objective "Terminate a loop" does not accept the assignment's solution

The objective Terminate a Loop does not accept it when I put a "break" before the relevant message.

The assignment says that I should immediately terminate the for loop, but the "Check work" button does not accept that solution.

Yes, the "Check work" error message indicates that it wants to see the relevant message, so the "solution" it will accept is obvious, but that solution is not what the assignment required.

Kara of Treehouse Support responded that "it works", and for further questions go ask the community.

So here I am, bothering you with my grumbles about this inconsistent objective. Feel free to ignore them.

3 Answers

Robert Manolis
STAFF
Robert Manolis
Treehouse Guest Teacher

Hi Carlo Hogeveen, I just tested out that challenge, and it passes with the break; statement just after the console.log('The loop has terminated...'); statement, which is intended. You wouldn't want to break before that statement, because then the message would never be printed, so why would it be there? :thumbsup:

I want want it before the message because that is what the objective describes that we should do. Notice that the objective says "immediately". Agreed, that would not make common sense, but it would make programmer sense in that it follows the requirement. I curmudgeonly object to the objective not accepting the instructed solution too.

Robert Manolis
Robert Manolis
Treehouse Guest Teacher

Hi Carlo Hogeveen, double check the wording please. Notice how it does not say to add the statement immediately. The challenge is not asking for the statement to be added immediately. It reads, "add the statement that immediately terminates the for loop". So it's just saying to add the statement, and makes no mention of where, when or how to add the statement except that it should be added once this condition is met: i === message / 2. And naturally, that would be added after the log statement, or the log statement would be obsolete.

So just to be clear, "immediately" is not referring to where or when to add the break statement, but just refers to how the break statement will immediately terminate the loop once it is called.

I know sometimes language itself can trip us up and lead to misunderstandings. Happens to me all the time. Important thing is to not let things like this add to our frustration since learning to code can already be frustrating enough, and frustration only makes learning harder. :thumbsup:

I do not know a statement (yet?) that I could add that would terminate the for-loop, but not immediately, so I do not get your assertion that "immediately" differentiates the break statement from another loop-terminating statement.

If I leave the word "immediately" out of the assignment, it would still be a good assignment for the answer it wants to hear.

Note that in the same sentence the condition is also mentioned as a qualifier for the statement's placement. Given that AFAIK there is no deferred for-loop terminating statement, I can only interpret "immediately" as a placement qualifier too, just like the condition.

So I have still reason to regret, that the "Check work" button does not accept the strictly correct answer too.

I hope that the tone of my previous messages conveyed, that concerning this issue my frustration is extremely mild.

Robert Manolis
Robert Manolis
Treehouse Guest Teacher

Agreed that the word "immediately" there is a bit superfluous since there isn't really a "delayed" way of breaking out of the loop, or a need for one. But that doesn't change the meaning, use or purpose of the word or wording.

If the challenge said "Immediately add the statement that terminates the...", then perhaps you would have a point.

But it doesn't say that. It says, "Add the statement that immediately terminates the.."

Clearly, the "immediately" is a qualifier of the statement to be added, and not the when, where, or how to add the statement. :smiley:

I guess we have to agree to disagree. Thank you for taking the time to elaborate on your viewpoint.

Robert Manolis
Robert Manolis
Treehouse Guest Teacher

No worries, Carlo. Please have a great rest of your day, and keep up the awesome coding and learning. :clap::smiley: