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 trialAdil Ismaaeel
9,438 PointsHow to call console more than once in javascript for loop?
Im not sure what I am doing wrong and no where I search seems to give me an answer that makes sense. When I write out the code as i have it this is the message that I get. " You need to log out EVERY number from 4 to 156 to the console. Your loop calls the console.log() method 1 times." Please help
var num = '';
for ( var i = 4; i <= 156; i++) {
num += '<div>' + i + '</div>';
}
console.log( i );
how to call console more than once in javascript for loop? You need to log out EVERY number from 4 to 156 to the console. Your loop calls the console.log() method 1 times.
1 Answer
KRIS NIKOLAISEN
54,972 PointsMove your console.log() method inside the loop. Then it will be called with each iteration. Once there console.log( i );
is good enough. No need for concatenating divs.
Adil Ismaaeel
9,438 PointsAdil Ismaaeel
9,438 PointsAwesome that worked thank you