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

Hello. Is my code wrong? Bummer: The console should display 5 the first time through the loop and 100 the last time.

script.js
let counter;
for (counter = 5; counter <= 100; counter++ ) {
  console.log(`The number is ${counter}`);
}

3 Answers

MD MONIRUZZAMAN
MD MONIRUZZAMAN
6,130 Points
for (let counter = 5; counter <= 100; counter++ ) {
console.log(`The number is ${counter}`);
}

You should avoid this line

console.log(`The number is ${counter}`);

& simply type

console.log(counter);

Your code is more than perfect but your answer need to be according to the question otherwise in most cases,system will not let you pass.BTW,you can initialize variable(count) inside the loop, if you wish to invoke the variable inside the loop.It looks clean & also good coding practice.

Hopefully it will helps. Happy coding.πŸ˜ƒ

Hey danon62,

You only have to log a number so you can remove template literals from console method.

Here's the final code:

let counter;
for (counter = 5; counter <= 100; counter++ ) {
  console.log(counter);
}

Hope this helps!

Clare Yeadon
Clare Yeadon
5,553 Points

Thank you! I was stuck here too but your answer helped.

The second solution has helped a lot, thanks very much!!!