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

Glen Kemp
Glen Kemp
5,181 Points

This is correct in my browser but not on here? Please help.

var numbers = '';

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

script.js
var numbers = '';

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

2 Answers

Gabbie Metheny
Gabbie Metheny
33,778 Points

You're already incrementing i in the condition in your for loop, so you can just use i to print to the console inside the for loop. Right now, while you're still technically getting the numbers, you're combining them all into a single string before printing them, like this:

// output:
456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156

This is not what the challenge is expecting, so that's why it isn't letting you pass. Let me know if it still doesn't work for you when logging i inside the loop instead!

Glen Kemp
Glen Kemp
5,181 Points

Thank you I've done it!