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

I'M SURE THERE AINT A TYPO HERE.

Please elaborate on where it's wrong.......

script.js
for (var num = 4; num <= 156; num+= 1){
}
console.log(num);

2 Answers

Benjamin Barslev Nielsen
Benjamin Barslev Nielsen
18,958 Points

I assume that the expected result was that you should log the numbers 4, 5, 6, ..., 156 in the console. However your code only logs 157, and this is because you do not have console.log(num) inside your for-loop.

The code should have been:

for (var num = 4; num <= 156; num+= 1){
    console.log(num);
}

Thanks

Hi Ben,

If you put your console.log() call inside the curly braces of the for loop, this will work just fine.

Steve.