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 trialJerry Kankelborg
4,885 Pointswhats the solution ?
heres my attempt
var num = 0;
for (var i=4; i<=156; i +=1){
num += 1;
console.log(num);
}
1 Answer
Luke Maslany
3,558 PointsThe main issue is that you are starting num with a value of 0. The first time you go through the loop it will increment num by 1 and then log itβs new value, 1, to the console.
You can simplify this by foregoing the num variable and logging the for loop index to console instead. For example:
for (i=4;i<=156;i+=1) {
console.log(i);
}
Steven Parker: Ah - now I see what you mean. I had added it as a comment as I hadn't scrolled down far enough on my phone to see that Add an Answer was a different section. :)
Jerry Kankelborg
4,885 Pointsmakes sense. thank you
Jerry Kankelborg
4,885 Pointsthank you !
Steven Parker
231,275 PointsSteven Parker
231,275 PointsLuke Maslany β why not post an answer instead of a comment? This will allow voting and give Jerry the option of selecting it as "best answer".