Didn't log


#1

I wrote:

for (var i = 105; i <= 1; i - 5) {
console.log(i);
};

It says:

Oops, try again. Your loop didn't log 100 to the console!

I don't know what it means by this.


#2

Will this not cause an infinity loop?

you do i - 5, but then each time your i will be 105 again, and never becomes zero. You need to do

var i = 105; i <= 1; i  = i - 5

also, if you take steps of 5, it will only take around 20 times before i is zero, not logging 100 times, but only logging 20 times


#3

It won't cause an infinity loop, I checked it. Thanks for the help @stetim94 .


#4

It still doesn't work.


#5

I do console.log(i) inside the { } of the "for" loop, right?


#6

Yes, you do. And i have a bit of problem with my console, give me a second. Do you have any output?


#7

No, I don't have any output.


#8

Long day, i should go to bed. Anyway, this loop will never execute, why?

Because of this:

var i = 105; i <= 1;

105 is bigger then 1, so the condition is true, so the loops end it should be the other way around:

var i = 105; i >= 1;

now the loop decreases until it is 0, then it stops because condition is met. now you do need i -=5 otherwise you will have a infinity loop.


#9

Ohhhhh, thank you so much I never even noticed that!