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 Create a for Loop

Lost on this for loop..........

Im missing the code to execute the . for loop in the curly braces can someone please explain what it is and why its like that?.?.?

script.js
for (var i = 4; i < 157; i+=1){

}
console.log(i);

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Ben! You've got your for loop set up splendidly, but then it doesn't do anything. The curly braces denote the block of code that we want to run each iteration of the loop. But your block is empty. If I move your console.log(i) inside the for loop, the code passes!

On a side note, the variable i is not defined in the global scope. This means that the variable is only accessible while the for loop is running. Trying to access that variable outside the loop will generate an error.

Hope this helps! :sparkles: