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 trialPeter Retvari
2,566 PointsJavascript: simplify-repetitive-tasks-with-loops/create-a-for-loop: Dears, I stucked in this task.
Maybe I don't understand the question. Should I write to the console numbers, from 4 to 156, right? Like: 4,5,6.....155,156 and finish. I used this for loop:
script.js: for (var i=4;i<157;i+=1){ console.log(" "+i); }
for (var i=4;i<157;i+=1){
console.log(" "+i);
}
1 Answer
Thayer Y
29,789 PointsHi
for (var i=4;i<157;i+=1){ //the challenge ask to loop numbers (4 to 156) not 157
console.log(" "+i); // there's no need to quotes(" ") and plus sign(+)
}
for (var i = 4; i <= 156; i++){ // so your loop should be like this
console.log(i);
}
Peter Retvari
2,566 PointsPeter Retvari
2,566 PointsDear Thayer,
Thanks for your quick reply. I know that the challenge is to write number from 4 to 156, and the first part of my code is ok: for (var i=4;i<157;i+=1), (because its not i<=157, its i<157. However I mixed up with the document.write method, that is why I put " " before the items, due to the space between the numbers. I deleted the quotes and after worked perfectly.