‫So now we're going to do a little challenge called Fizzbuzz.
‫And many of you have probably heard of this and have done this.
‫And this is a question that's often asked in job interviews for developer positions.
‫So basically this combines loops and conditionals, which is what we've been talking about in the past
‫few sections.
‫So as far as the steps, we need to write a program that prints the numbers from 1 to 100 and for multiples
‫of three.
‫So any number between 1 and 100, that's a multiple of three.
‫You want to print the string fizz instead of the number for multiples of five.
‫You want to print the word buzz instead of the number, and for for numbers, which are multiples of
‫both three and five.
‫You want to print Fizzbuzz okay hints.
‫You can use the modulus operator to check if a number is divisible by another number.
‫You can echo obviously line break tags to add a break after each number.
‫So so that they're, you know, stacked one on top of each other.
‫So pause the video and try it out.
‫You can use any kind of loop you want you can use for a while whatever.
‫So I'm going to get started and I'm going to use a for loop.
‫So let's say for and remember it's 1 to 100.
‫So for our initializer here we're going to set that to one not zero.
‫And since we want to go to 100 we want to say stop this or keep this going as long as I is less than
‫or equal to 100, okay.
‫If it gets over 100, then it will stop.
‫And then of course we need our update or our increment.
‫And for now, let's just echo out whatever I is.
‫And then I'm also going to echo out a line break down here at the bottom.
‫And just to make sure that works, let's reload and we get from 1 to 100.
‫All right.
‫Now we're going to have to check a few things here.
‫Let's start with the first which is for multiples of three print fizz instead of the number.
‫So what we can do is say if.
‫Let's say if I and the way we can check to see if it's a multiple of three is simply by using the modulus
‫operator and then three and the remainder should be zero.
‫Okay.
‫And if that's true then we're going to echo out a string of fizz.
‫And then we'll have an else.
‫And in that else will echo out the number.
‫So let's try that.
‫And now every every multiple of three you can see has the string of fizz.
‫So three, six, nine, 12, 15 and so on.
‫Now for multiples of five we want to print buzz.
‫So let's do an else if so right here we'll say else if no space there.
‫And we'll open that up.
‫And then when it closes, else should come immediately after that.
‫So in the else if we want to check to see if it's divisible by five.
‫So let's do I.
‫And then percent five and the remainder should be zero.
‫And if that oh I forgot my curly brace before the else if so right here.
‫We should do that.
‫So if that's true, then let's echo out a string of buzz.
‫So we'll reload that.
‫And now you can see 510.
‫Uh, 15.
‫Now, 15 is a multiple of both three and five.
‫So that should say fizzbuzz.
‫I'm sorry, that's not 15.
‫That's that's 12.
‫This is 15.
‫So it should say Fizzbuzz.
‫So let's add one more condition in here.
‫In fact, I'm going to have that be the first condition we check for.
‫So this will actually be an else if.
‫And then let's go above that and let's say if.
‫All right.
‫Just move this like that.
‫And we'll say if I and we want to check for both.
‫So modulus three equals zero and.
‫I.
‫Uh, modulus five is equal to zero.
‫So if there's a zero remainder then we want to echo out fizzbuzz.
‫All right.
‫So let's go ahead and try that.
‫And now you'll see 15 is Fizzbuzz 30 is Fizzbuzz.
‫Because that's also a multiple of three and five.
‫Then we got what's next 45 6075 and so on.
‫All right.
‫So that's pretty much it.
‫Now you can shorten it by instead of checking for both of these three and five, you could just check
‫for 15.
‫Because if it's divisible by 15 then we know that it's divisible by both or it's a multiple of both
‫both three and five.
‫All right.
‫So let's try that.
‫We'll reload and we get the same result.
‫So if you did something different, absolutely fine.
‫As long as you get this result, then it's correct.