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

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!