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 trialIgor Yamshchykov
24,397 PointsPrevious 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
Gene Osborne
8,630 PointsReturn 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.
Kirby Abogaa
3,058 PointsAs 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
1,104 PointsIgor 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
24,397 PointsDid 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.
mjmj
18,664 PointsYou are missing closing bracket for one: ....(var i = 0; i <=10 ; i += 1)....
Igor Yamshchykov
24,397 PointsIgor Yamshchykov
24,397 Pointsit's not, but it still might be confusing to somebody.