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

Jerry Kankelborg
Jerry Kankelborg
2,110 Points

whats the solution ?

heres my attempt

var num = 0;
for (var i=4; i<=156; i +=1){
  num += 1;
Steven Parker
Steven Parker
185,871 Points

Luke Maslany — why not post an answer instead of a comment? This will allow voting and give Jerry the option of selecting it as "best answer".

1 Answer

The main issue is that you are starting num with a value of 0. The first time you go through the loop it will increment num by 1 and then log it’s new value, 1, to the console.

You can simplify this by foregoing the num variable and logging the for loop index to console instead. For example:

for (i=4;i<=156;i+=1) { 

Steven Parker: Ah - now I see what you mean. I had added it as a comment as I hadn't scrolled down far enough on my phone to see that Add an Answer was a different section. :)