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

Unable to console log this from 4 to 156.

tried reviewing the concepts in the associated video somehow still lost in this.

script.js
var number= '';

for (var i =4; i <=156; i += 1) { 
  i += 'number' + i + 'number';
} 
console.log(number + i);

2 Answers

Emre Karakuz
Emre Karakuz
9,162 Points

First of all, you don't need a varible name = ' ' to do this challenge

2-)You are already increasing the i value in the loop decleration with this code : ( i=4 ; i<=156; i += 1). So you dont need to increase it in the function block (between {})

3-) console.log is called after the for loop which means it will log the last i variable (156) to the console. To fix this, write console.log(i) inside the for loop.

for (var i =4; i <=156; i += 1) { 
  console.log(i);
} 

When using a variable, such as number in this case, you aren't supposed to put quotes around it when referencing it. The quotes make JavaScript interpret it as a string. For this exercise, however, you don't need the number variable. Just the i variable should suffice. Also, your console.log() statement should be inside the for loop, not underneath it. Try this instead:

for (var i =4; i <=156; i += 1) { 
  console.log(i);
} 

I loved your explanation as well. I am truly grateful for this. I guess I still have a lot of practice and learning to go.

Basically what katherine said, this was how I wrote it.

for (var i = 4; i <= 156; i++){
   console.log(i);
}

the "i++" increment is shorthand for "i += 1" that you may see in some other languages.