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

Rose M
Rose M
2,720 Points

How do I do create this loop?

The question states.

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.

script.js
for(var num=4; num<=4; num+=1){
}console.log( num = 156);

2 Answers

Dmitry Polyakov
Dmitry Polyakov
4,929 Points

You need to change your 2nd parameter for num inside parentheses, this is your ending condition: i<=156 and console.log just num.

Rose M
Rose M
2,720 Points

Could you show me cause I really don't understand what you are saying. Cause when I put it in it nows say error.

for(var num=4; i<=156; num+=1;){ }console.log(num);

Dmitry Polyakov
Dmitry Polyakov
4,929 Points

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