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 trialBlake Atkerson
2,797 PointsI am unsure why this differs from the instructor's example
I copied the same logic from the video after trying to omit the use of the "html" variable. Where did I go wrong?
var html = '';
for (var i = 4, i <= 156, i += 1) {
html += i;
}
console.log(html);
2 Answers
Tiffany McAllister
25,806 PointsYou have a syntax error in your for loop. You need to use semi-colons between each statement rather than commas.
You are also logging your html variable to the console outside of the for loop. You don't need the html variable. You just need to log the i variable to the console inside the for loop :)
Gunhoo Yoon
5,027 PointsThere are two mistakes.
Your initial
html
variable is a String type.You used comma two separate each stage of for loop instead of semi-colon.
Second one is simple syntax error so I'll go over first one.
What you will get after first iteration is String 4 not Number 4. '4' !== 4
From then the + operator is used as string concatenation rather than arithmetic addition. Because you are adding Number to a String. So your final result becomes something like '456...........156'
To fix this change your initial html
value to Number and fix the syntax error in your for loop.
Blake Atkerson
2,797 PointsThanks for your help!
Blake Atkerson
2,797 PointsBlake Atkerson
2,797 PointsThanks. That worked! I was just making it <em>more</em> complicated :/