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 trialHemant Kumar
870 PointsPlease Help Guyz, its so easy but i am get stuck into it
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.
for (var i = 3; i<156; i++){
console.log(i);
i+=1;
}
5 Answers
William Li
Courses Plus Student 26,868 PointsInitial value of i and end condition are not right, also you don't need to increment i in the loop body.
for (var i = 4; i<=156; i++){
console.log(i);
}
Joel Smith
14,779 Pointsfirstly, start with your index variable (i) at 4, because the loop begins by running once. Then take out the additional i+=1 as you already have 1 being added to i for each loop in the arguments. it should look like this-
for (i=4, i<156, i+=1){ console.log(i); }
I hope this helps
William Li
Courses Plus Student 26,868 Pointsumm ... you missed the var keyword for i declaration, also, the end condition should be i<=156
Joel Smith
14,779 Pointsyeah, you're right.. I didn't mean to point in the wrong direction by making those mistakes.. but the main point I was making was that he needed to start at i=4 and to remove that extraneous i+=1.
Thanks. :)
Hemant Kumar
870 PointsMany thankx guyz
Sobin Sebastian
5,348 Pointsfor (i = 4; i <= 156; i++) { console.log(i); }
Rich Braymiller
7,119 Pointswhat are you talking about? makes no sense...im reading all these responses and am more confused about this challenge!