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

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,014 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,539 Points

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

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