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 trialZeeshan Dawood
7,210 PointsI'm not understanding why the for loop is not working for this challenge
What am i missing. I know the first statement runs before the loop starts. 2nd statement is conditional meaning it will run until that condition is false 3rd adds additional to i after each time the loop runs the code that is suppose to execute should write i plus a space then the console should log it.
var html;
for (i=4; i<=156; i++) {
html = i + " ";
console.log(html);
}
2 Answers
Roberto Alicata
Courses Plus Student 39,959 PointsYou simply have to write the console.log of the "i" variable every cycle of the loop
for (i=4; i<=156; i++) {
console.log(i);
}
shakilsultanali
3,113 PointsZeeshan,
Your code is working perfectly well at my end, and Roberto's method is correct if you're only looking to display the loop-count then you should just type
console.log(i);
But if you are going to append something with it for instance,
html = i + " number";
then you should use:
console.log(html);
My code is below which I used...
<html>
<script>
var html;
for (i=4; i<=156; i++) {
html = i + " number";
console.log(html);
}
</script>
</html>
Roberto Alicata
Courses Plus Student 39,959 PointsYes it works but it isn't what the challenge asked.