I'll write.
So it's time for another quick problem set.
This time we're covering wild loops and Javascript.
So there are three problems here and rather than you writing code I'm actually giving you code and all
I need to do is evaluate what is printed out.
So here's the first one.
Take a moment pause the video if you need to but please don't just copy the code to your console unless
you want to check the answer that you've come up with on your own.
So the answer to this one is that it prints out the odd numbers from 1 to 9.
And the reason that it does that starts with not equal to 1.
Wow.
Nahm is less than equal to 10.
Print out the number so we print out one and then we add two.
So then we go through with the number three.
That's less than 10.
We print out three and then we go to 5 and it keeps going until we're at nine.
Cancel that log nine nine plus equals two.
So then we're at 11 and that's no longer less than or equal to 10.
So just to verify that if I opened up my javascript counsel here and I paste that in you'll see I get
1 through 9.
There is one small confusing thing which is that it looks like it printed out 11.
But you'll notice it's slightly different.
There's this arrow here that we don't see on any of the other ones and we also don't have the sort of
link next to 11 so what's actually happening here is that the consul is showing us the value of the
last evaluated expression.
So even though it's not printed out to is still added to 9 so 11 is the last thing that is evaluated
and the Crome Council just shows that to us without printing it out.
So let's move on to the next one.
Take a moment pause the video if you need to take a longer look and then we'll go over the solution
.
So this one is going to print out all the multiples of 4 between 1 and 20.
So Gnome starts at 1.
While Nahm is less than or equal to 20 so we have an if statement inside of a loop.
And this if statement is checking if a number is a multiple of four so if number mod 4 is equal to zero
which means does 4 divide evenly.
If it does printed out.
So the first time through we go through 1 2 3 4 and now for maade for is zero.
So we print out the number 4 and then we go through again with 5.
Nothing happens 6 nothing happens 7 nothing happens 8 8 mod 4 is also 0.
So with constant out log number.
So just to verify that.
Open up the con..
You can paste it in and you see we get 4 8 12 16 and 20.
So one more here.
Take a moment Pozza screen again will go over a solution in just a second.
So this one's a little bit tricky.
It's actually an infinite loop so you'll see that number starts at 100 and this code will run.
While the number is less than 150 So 100 is less than 150 then we're printing out a number plus one
.
But the important line is here where subtracting one from number every time.
So it starts at 100 and we're going the other direction we're subtracting.
So it's always going to be less than 150.
So I'm not going to run this in the con..
But if I did it would tell me I have an infinite loop