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

Trying to select numbers 4 to 156 in this code challenge. No idea how to do it.

I learned how to select numbers from 1 to 10, but I'm stumped when it comes to selecting a specific set of numbers in between?

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

1 Answer

Matthew Lanin
seal-mask
.a{fill-rule:evenodd;}techdegree
Matthew Lanin
Full Stack JavaScript Techdegree Student 8,003 Points

Since i is going to be the variable that we increase and that counts our numbers between, 4 and 156, we put i in the parenthesis of the console.log() statement.

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

Also, since we know we're starting at 4, we can just initialize i to 4, and remove the i >= 4 portion of the for loop.

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

So with that, we log to the console everything between (and including) 4 and 156.