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 trial

JavaScript JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops Create a for Loop

Please I need help with this challenge, how can I log the numbers starting with 4?

How can I create a for loop loging every number starting from 4 up to 156?

for (var counter=0; counter<156; counter+=1) { 
console.log (counter +4)

2 Answers

Raffael Dettling
Raffael Dettling
32,999 Points

You have to count from 4 to 156. Start with 4 and add 1 every time the loop runs

for (var counter = 4; counter <= 156; counter += 1) { 
console.log (counter)

Thank you!! :)

Charles Wanjohi
Charles Wanjohi
9,235 Points

initialize your counter to 4 check the counter is less or equal to 156 and keep incrementing by 1. Currently let keyword is preffered to var in loops

for (let counter = 4; counter <= 156; counter += 1) { console.log (counter) }