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 trialMichael Lawinger
33,581 PointsJavascript For Loop
The Challenge Question Is: Create a for loop that logs the numbers 4 to 156 to the console. To log a value to the console use the console.log( ) method. Below is the Code.
var log;
for (i=4; i <= 156; i += 1) {
log += console.log(i);
}
console.log(log)
2 Answers
andren
28,558 PointsYou don't need to do anything but call the log method within the loop. Like this:
for (i=4; i <= 156; i += 1) {
console.log(i);
}
Also the console.log
command does not return any data so storing its return in a variable is pointless. If you wanted the log
variable to contain the numbers 4 to 156 you would have to add i
to the log
variable, not the return of the console.log
command.
james south
Front End Web Development Techdegree Graduate 33,271 Pointsyou don't need a log variable or any code outside of the for loop. once your loop is set up properly, inside just log your loop variable to the console. console.log can be called directly in the loop.