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 Working with 'for' Loops Create a for Loop

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

script.js
for ( let i = 5; i < 100; i++ ) {
  console.log (i);
}

3 Answers

Hi Ndhokoyo!

You are so close!

Unfortunately, your loop will quit after logging 99.

This passes:

for ( let i = 5; i <= 100; i++ ) { // Will get to 100
  console.log (i);
}

This would also work:

for ( let i = 5; i < 101; i++ ) { // Will get to 100
  console.log (i);
}

I hope that helps.

Stay safe and happy coding!

I don't understand. In Guils video, there is this whole thing there : function getRandomNumber(upper) { return Math.floor( Math.random() * upper ) + 1; } and now there's none of that and we're the value "counter" in console.log.... please help

Hi Didier!

This is just a different kind of (more hard-coded) type of looping structure.

The lower value is 5 and the upper value is 100

And this will log to the console:

5
6
7
8
.
.
.
97
98
99
100

More info:

https://www.w3schools.com/js/js_loop_for.asp

https://www.freecodecamp.org/news/javascript-loops-explained-for-loop-for/

https://www.freecodecamp.org/news/master-the-art-of-looping-in-javascript-with-these-incredible-tricks-a5da1aa1d6c5/

I hope that helps.

Stay safe and happy coding!