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, Arrays and Objects Simplify Repetitive Tasks with Loops The Refactor Challenge

Igor Yamshchykov
Igor Yamshchykov
24,397 Points

Previous quiz question.

At previous quiz there is a question about exiting the loop.

Which of the following statements will make the JavaScript interpreter exit a loop even when the loop condition is still true?

The correct answer is break; which is actually logical, but return will also break the loop, so that might be correct answer as well.

4 Answers

Return will exit the current subprogram or method, which is not the same thing as exiting the loop.

In some cases they may have same practical outcome (like causing a loop to terminate), but it is not exactly the same.

Igor Yamshchykov
Igor Yamshchykov
24,397 Points

it's not, but it still might be confusing to somebody.

Kirby Abogaa
Kirby Abogaa
3,058 Points

As I understand it, a return function can ONLY run when the condition becomes false.

A break function immediately terminates a program when it reaches its turn to function regardless if the condition statement was met or not.

Chris Harkin
Chris Harkin
1,104 Points

Igor Yamshchykov hay am stuck on one of the previous quiz questions two.

Quiz Question 1 of 6 Please fill in the correct answer in each blank provided below.

Complete the code below to create a for loop that executes 10 times, writing the value of the variable i to the document each time: my answer

for  (var i  = 0; i <=10 ; i += 1 {
    document.write(i);
}

I have also tried <10 and less than 11

can you help

Igor Yamshchykov
Igor Yamshchykov
24,397 Points

Did you figure out the correct solution already ? I'm sorry for late response. I'm not sure what was the correct solution, but I suppose you might try something like

for  (var i  = 0; i <=10 ; i += 1 {
    document.write(i);
    break;
    // maybe break will need condition here
}

please try.

You are missing closing bracket for one: ....(var i = 0; i <=10 ; i += 1)....