Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Loops Working with 'for' Loops Create a for Loop

Rotem Aslan
Rotem Aslan
Full Stack JavaScript Techdegree Student 9,895 Points

Create a for loop that logs the numbers 5 to 100 to the console. Use the console.log() method to log a value to the cons

why this code not working ?

var res;
for(let i=0;i<=95;i++){
  res += 'i='+i 

1 Answer

Rohald van Merode
.a{fill-rule:evenodd;}techdegree seal-36
Rohald van Merode
Treehouse Staff

Hi Rotem Aslan 👋

What you're doing with this loop is create one large string that would end up looking something like i=0i=1i=2i=3i=4i=5.....

For this challenge you'll want to log each number individually to the console. I'd suggest to move the console.log inside your loop and print the i on every iteration. Doing it this way you won't be needing a separate res variable either.

Also please notice that the requirement for the challenge is to print the numbers 5 to 100 while currently your loop starts at 0 up to 95.

Hope this helps 🙂