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 trialdanon62
4,354 PointsCreate 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.
let counter;
for (counter = 5; counter <= 100; counter++ ) {
console.log(`The number is ${counter}`);
}
3 Answers
MD MONIRUZZAMAN
6,130 Pointsfor (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.π
Rabin Gharti Magar
Front End Web Development Techdegree Graduate 20,928 PointsHey 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
5,553 PointsThank you! I was stuck here too but your answer helped.
danon62
4,354 PointsThe second solution has helped a lot, thanks very much!!!