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 trialAgnes Caringal
6,239 Pointswhat's wrong with this.... FOR LOOP challenge
parse error...what do you mean?
var value = '';
for ( var i = 4; i =< 156; i += 156) {
console.log('value');
}
1 Answer
Greg Kaleka
39,021 PointsHi Agnes,
There are a few issues with your code:
- You are getting a parse error because you have =< instead of <= (note it looks the way you say it: "less than or equal to"
- You only want to increment by one each time through the loop, so that you hit every number between 4 and 156.
- 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.
- 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
6,239 Pointsthanks, now i got your point and i understood, thanks Greg Kaleka :)
Greg Kaleka
39,021 PointsHappy to help!
Agnes Caringal
6,239 PointsAgnes Caringal
6,239 PointsCHALLENGE: 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.