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

For loops, i am not sure how to answer this code challenge on For loops.

creating a For Loop for the number 4 to 156

script.js
var number = ' ';
for (var i = 1; i <= 152; i += 1) {
    console.log(number);
}

2 Answers

Tabatha Trahan
Tabatha Trahan
21,422 Points

Hi Priscilla. Your for loop is so close to being the correct answer for the challenge. Take a look at your initializer and your condition again as you read what the challenge is asking. It wants you to start at 4 and go up to (including) 156. If you set i to equal 4, and continue looping until i is greater than or equal to 156,(so while i is less than or equal to 156 you keep looping) you should be good to go.

Thank you Tabatha...

In addition to what Tabatha Trahan said, in the body of the loop you also need to be logging the current value the loop is on. Logging the number variable will just print an empty string for however many times your loop is set to run.

Thanks Adam..