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

I have a problem with javascript for loops challenge

I am having a problem getting this challenge to pass, what am i doing wrong?

script.js
var number = ' ';

for ( var i = 4; i <= 156; i += 1 ) {
  number += i;
}

console.log(number);

2 Answers

You 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;

thank you for that. one day I will understand javascript.

Yes. You have to keep practicing and never stop learning. Good luck!