We have another exercise that has to do with loops exercise six. So for this exercise, your assignment is this, like you to write a loop that will display any number between one and 100. That is a multiple of both three and five. So as to be multiples of both three and five. All right, so you're going to be using the modulus operator. With that this exercise similar to some exercises we've done in the past.
Go ahead and give this a try. pause the movie. Once you feel you're ready to move on started again and we'll go through it together. Okay, let's look at how we might solve this problem though. Once again, I think it's helpful to write out what you need to do. So first Then we need to do is we need to loop through one to 100.
Okay, to me that says right away a for loop because I know exactly the starting number and I know the ending number. So the starting number is going to be one, so I set i equal to one. Now I'm going to test to see if i is less than or equal to 100 because that's when we want to exit out of the loop as soon as it's greater than 100. And then we want to increment i. Alright, so that's our loop. So we need to go through loop through one through 100. All right, the next thing I need to do is I need to get the mod of three and I need to get the mod of five Then I need to check are both equal to zero?
If so then then I need to display that number. Okay, so that will help give us direction and also helps us identify what variables we're going to need. So I'm going to declare some variables up here. I'm going to declare one and call it mod three, and also a mod five. Those are two variables I'm going to use to store the results of the mod. So let's get the mod of three mod three equals I, modulus operator three looks.
Now let's get the Modify. So remember, the modulus operator operator will put the remainder In the variable, that's what we're getting here. So I'm on five, set that equal to i plus five. So let's see if there's a remainder if the numbers divided by five. So we check to see if there's remainder, the numbers divided by three and one of the numbers divided by five. Now we need to check to see if they're both equal.
So this is a question which we can solve with an IF conditional. If mod three equals zero, strict equality operator. Now we need a logical operator and mod five because it has to meet both conditions. And mod five is equal to zero. If it meets both of those conditions and evaluates to true. Then we want to console log the number which is I okay, All right, that should do it for us.
Let's save this and test this out. Jump to the browser, paste in that path. Let's display the console. Alright, looks like we have a series of numbers here. And all of those are divisible by three and five. Tell me looking at them.
Alright, so looks like that was successful. So that was the last exercise with control structures. We will continue to use control structures. We will add to them as we learn additional things throughout this course. So we're not leaving them. Just as with other topics we've had in this course we continue to build on them.
So let's move on to the next section.