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

How 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

script.js
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
KRIS NIKOLAISEN
54,167 Points

Move 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.

Awesome that worked thank you