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

Agnes Caringal
Agnes Caringal
6,239 Points

what's wrong with this.... FOR LOOP challenge

parse error...what do you mean?

script.js
var value = '';

for ( var i = 4; i =< 156; i += 156) {
  console.log('value');
}
Agnes Caringal
Agnes Caringal
6,239 Points

CHALLENGE: Create a for loop that logs the numbers 4 to 156 to the console. To log a value to the console use the console.log( ) method.

1 Answer

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Agnes,

There are a few issues with your code:

  1. You are getting a parse error because you have =< instead of <= (note it looks the way you say it: "less than or equal to"
  2. You only want to increment by one each time through the loop, so that you hit every number between 4 and 156.
  3. You are only logging the string 'value', and not an actual number. You need to use the same variable you have in your for loop - i.
  4. There's no need to use a variable named 'value' outside your for loop.

Here's the solution:

for (var i = 4; i <= 156; i += 1) {
  console.log(i);
}
Agnes Caringal
Agnes Caringal
6,239 Points

thanks, now i got your point and i understood, thanks Greg Kaleka :)