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 trialKORAXE IUHMAGEON
Courses Plus Student 8,486 PointsWhat am I doing wrong? this should count from 4 to 156
What am I missing
var counter = '';
for (var i = 4; i <= 156; i +=1) {
counter = i;
}
console.log(counter);
2 Answers
Jordan Watson
14,738 PointsRight I see what you are trying to do here are trying to update the counter variable with the for loops index more or less.
var counter;
for (var i = 4; i <= 156; i ++ ) {
counter = i;
}
console.log(counter);
Okay this is what Ive got! You created the variable as if it held an empty 'String' When its a integer that is getting placed in it none the less. This should console log 156. Hope that helps. Your code works I don't know why you had trouble with it?
Check the developer tools console for the count result :)
Simon Coates
28,694 Pointstry :
for (var i = 4; i <= 156; i +=1) {
console.log(i);
}
console.log needs to be inside loop.
Simon Coates
28,694 PointsSimon Coates
28,694 PointsIf you run your code using developer tools, it will only output 156. The counter stores the value for i from the last iteration of the loop. You can often test javascript code to see if it does what it's meant to.