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 trialGareth Davies
3,919 PointsI have a problem with javascript for loops challenge
I am having a problem getting this challenge to pass, what am i doing wrong?
var number = ' ';
for ( var i = 4; i <= 156; i += 1 ) {
number += i;
}
console.log(number);
2 Answers
Karan Nahar
16,157 PointsYou have to log every number from 4 to 156.Here you are adding numbers like 4+5+6.... to your number variable. You just have to output the numbers. That can be done simply by
for (var i = 4; i <= 156; i++) {
console.log(i);
}
And one more thing your number variable is a empty string not a number. You just declare a number by
var var_name = your_number;
//or declare the variable and assign it afterwards
var number;
number = 1;
Karan Nahar
16,157 PointsYes. You have to keep practicing and never stop learning. Good luck!
Gareth Davies
3,919 PointsGareth Davies
3,919 Pointsthank you for that. one day I will understand javascript.