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, Arrays and Objects Simplify Repetitive Tasks with Loops Create a for Loop

I keep getting Bummer when the code is correct. I ran it in the Workspace and it worked perfectly.

On the For Loop exercise to console.log 4-156 my code is correct but it keeps saying I'm wrong. I ran it in the Workspace from the previous video and it worked perfectly. It wrote the numbers 4-156 to the console. for ( i = 4; i <= 156; i += 1 ) { console.log( i + ' '); }

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

1 Answer

Umesh Ravji
Umesh Ravji
42,361 Points

Hi John, it's just the space you are adding to each number, I'm not sure how the engine tests the output, but the solution is just to remove it. Also, make sure to include the var (or let/const) keyword when making variables, while it won't hurt here without it, in the future it may create issues :)

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

Thanks Umesh. I found that out also. Good comment on declaring the var in the For condition but the videos don't do that. Thanks for the insight!