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 trialDinasha Rollins
1,464 PointsI did exactly like the example but I used 4 and 156 but its not working and i do not understand why
the wording of the questions are confusing please break this down better because im frustrated and confused
var numbers = '';
for ( var i = 1; 4 <= 156; i += 1 ) {
numbers += '<div>' + i + '</div>';
}
console.log(numbers);
2 Answers
KRIS NIKOLAISEN
54,972 PointsSome hints:
- Since you are counting from 4 initialize i = 4
- The condition 4 <= 156 is always true so you have created an infinite loop. Use a value that increments instead
- You are logging to the console so won't need <div>. You can eliminate that and related code by just logging i inside your loop instead
Dinasha Rollins
1,464 PointsI did everything you told me to so it still does not work
Dinasha Rollins
1,464 Pointsthank you I for helping me figure out the problem
Gabriel Plackey
11,064 PointsIf you are still struggling with this, here is the correct answer. Kris was pointing you in the right direction without giving it to, but sometimes it can help to see the actual code.
We want i to equal four because we are starting at 4. Then you aren't checking 4 to be equal to or less than 156, that will never be true so it's running infinitely. We need to check i the variable were using as an index and increasing each time to be equal to or less than 156 to continue the loop or not. Then we just want to console log i, to console log each number in between the two.
for ( var i = 4; i <= 156; i += 1 ) {
console.log(i)
}
KRIS NIKOLAISEN
54,972 PointsKRIS NIKOLAISEN
54,972 PointsCan you post your updated code?