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

scott Walker
scott Walker
2,506 Points

i honestly thought this was right

initally i thought as it was a number it was asking to be logged as long as i converted it from a string to an interger should be fine no?

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

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,858 Points

Hi scott Walker

You're really close. There are just a couple errors (One syntax and One language).

First, in the for loop conditional, there shouldn't be a semicolon at the end (for the increment). The semicolon in JavaScript represents a statement end, and this is not the end of the statement as the opening curly brace for the bod of the loop needs to be executed. When you put a semicolon after the increment, the JS interpreter reads it and "go no further with this statement, instead of continuing into the body.

Second, the variable i is already a type Integer, so there is no need to try and parse the value. You simply just use the variable.

Added Note: While spacing doesn't matter (for the most part) in JavaScript, it is good practice to keep things spaced according to the general consensus on formatting. For example, no space after the opening parenthesis. No space before the semicolon. It's also best practice to use the ++ to increment instead the the +=1. I've reformatted the code, with the 2 corrections just for a visual reference.

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

Otherwise, Nice Work!! :) :dizzy: