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 trialIris Wang
Front End Web Development Techdegree Student 8,288 PointsJavaScript Loops, Arrays and Objects Challenge 1
Hi there,
I'm suppose to create a For Loop to log numbers from 4 to 156, then use the console.log method to print out the numbers. The challenge keeps saying I have a syntax error and won't let me pass.
Can someone point out to me where and what the error is? Thank you!
var numbersAll = '';
var firstNumber = 4;
for (var = i ; i <= 156 ; i += 1 ) {
numbersAll += i + firstNumber ;
}
console.log(numbersAll);
3 Answers
Alexander Davison
65,469 PointsYou are far off, over-thinking this challenge a bit. JavaScript isn't that picky, and is smarter than you think :)
All you need to do is this:
for (var i = 4; i < 156; i++) {
console.log(i);
}
Good luck! ~Alex
Jacob Mishkin
23,118 PointsYou're really close on this one. The for Loop is correct, the only thing you need to do is console the variable i through the loop. You don't need to add other variables, since all we want is the value of i.
console.log(i);
I hope this helps.
Alexander Davison
65,469 PointsHowever, there another error, because she set "var = i" which causes a syntax error
Jacob Mishkin
23,118 Pointsyup, very true.
Iris Wang
Front End Web Development Techdegree Student 8,288 PointsHi everyone,
Thank you so much for your input ! Yes I realised i set var = i, which is wrong.
Thank you for pointing that out! Appreciate it very much ! =)
jayshi
5,950 PointsHi Iris,
First, you had some syntax error in the for loop conditions. "for (var = i ; i <= 156 ; i += 1 )" , here i guess you mean "for(var i= firstNumber; i<= 156 ; i+= 1)";
Second, you put "console.log(...)" outside of the for loop, so it will only be executed once.
There are other errors, but those are more like logic error.
Jay
Iris Wang
Front End Web Development Techdegree Student 8,288 PointsHi jayshi,
Yes I looked through all the comments and I found out what was wrong. Thank you so much for the helpful input! I appreciate it very much! =)
Jacob Mishkin
23,118 PointsJacob Mishkin
23,118 Pointsyou need to either change the number to 157 or add an <= in your condition.
Alexander Davison
65,469 PointsAlexander Davison
65,469 PointsThis code challenge is a little weird. I know that this will count from 4 to 156, but the challenge is expecting "i < 156", which is 4 to 155.