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

Not sure of my error.

Please help with my code. I am not sure where my error is to get my code to run. Thanks. I need a counter to print to the console for 4 to 156 using a for loop.

script.js
var print = 0;

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

1 Answer

Alexandra Edwards
Alexandra Edwards
4,686 Points

Hi Nicholas, It looks like you're close. This was the solution I came up for that one:

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

Let me know if it still doesn't make sense for you. I'm happy to help.