Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Loops Working with 'for' Loops Create a for Loop

Frank Grillo
Frank Grillo
6,915 Points

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 32,424 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