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 Working with 'for' Loops Create a for Loop

Creating a for loop

Is this how I create a for loop?

for ( let counter = 5; counter <= 100; counter += 45 ) {

1 Answer

Mark Sebeck
Mark Sebeck
Treehouse Moderator 37,329 Points

Hi Frank. Yes that is the proper format for a for loop. But I’m confused why are you counting by 45? You want all number 5 to 100. So you start at 5 and count while counter <= 100. that’s all correct. But you want to count by 1. not 45. counting by 45 will give you the output: 5 50 95.

You want to end your for loop with: counter += 1

Not counter += 45