This and that or the other thing
If conditions can be a lot more complicated. So far our if conditions had only one condition within, but in reality, we could have a lot more conditions right in our one if statement. To do that we're going to use the and(&&), or(||) commands.
Video Transcript
00:00And this and that and this so like and this and like that and
00:08This is exactly what we're gonna be talking about right now
00:12easy and short and
00:14Very useful. So back in our fade-in object. We said we're only missing one thing
00:19we also wanted to have also basically the options of if we're at 12 to do one thing and
00:26And if we're in six to do basically the same thing
00:28so what I want to do is I'm just gonna copy this code and I'm just gonna create here an if statement and doesn't really matter where
00:35Here and let me just undo that breakline because we just did that for the sake of
00:40visuals
00:41All right. So now what I'm gonna do is I'm basically gonna create an if statement and I want to basically have a rule here
00:47That says if it's six or it's twelve and the way I do that
00:51I just approach first of all if it's if it's to six we already saw and if I want to also add or
00:58I'm gonna add here basically pipeline pipeline twice and then say our
01:03Equals equals twelve and what I'm doing here is I'm basically saying if it's six or it's twelve
01:09Then do this now if I save this and we run our application just one more time
01:13We're gonna see that now it's not six in the morning and it's not twelve
01:16So it's not gonna do that animation
01:18But if I go right ahead into here and I just add here oh to a six
01:22Then we'll see that oats are a middle and item is gonna I is gonna fade in
01:26And if we do it at 12 same deal
01:31Okay. Now, I want to show you a few more things
01:34I want to also show you that you the end and although it's not connected completely
01:38I want to create here another variable and I'm gonna call it
01:44Do
01:46Extra anim and it's gonna be a Boolean
01:49I'm just gonna set it to be true by default or you know it even better
01:52we're gonna add it as an extra parameter as
01:55Do extra anim and by default its value will be true, which basically saying that
02:01We're gonna do this animation
02:02But we want to add basically that if someone sends the do extra animation as false
02:06We want to basically skip this
02:08To be able to do that what I could do and I could very easily just go here and just set your if
02:13Do anim which we've seen this already before wrap this up and basically just push this whole thing into that if condition
02:20basically saying that if this and
02:23Only if do do do extra anim was true only then we're gonna do the rest of them
02:29another and a more smart way of doing it is basically combining the two together and what I'm gonna do is I'm just gonna
02:34Delete this and I'm gonna keep these inside of a round bracket and I close another round bracket for our biggest circle and just add in
02:42Between the end end and what that will do is basically say end. So here I'm saying basically if this is true and
02:49This is true
02:51notice how I put it in a round bracket because I wanted to make sure that I'm not if I didn't put here the
02:56Round bracket then I would have to have this and this is true or this in other words
03:01I would have to have true and the time 6 or that the time is 12, but that's not what we want
03:07We want it to be both that you do as extreme is true and one of these are true
03:12Okay, because it can't be 12 and the animation is not in other words
03:16If we didn't have here this closing these brackets and the time was 12, right?
03:22And the time was 12, but let's say do do extra animation was false. Let me show you that
03:28Let me just go ahead and show it to you if I do this and I send my animation and I say hey
03:32It's 12 o'clock. I'm gonna see this animation happening even though I don't want it to happen
03:37And the reason is is because in my code here, I thought that do extra animation. Oh, you know, that's we were a true
03:44Let me just set it to false. Okay, and if I set it to false notice what happens
03:51The animation will still happen even though we don't want it to happen. Now. The reason is is very simple
03:57Do that extra animation was false. So if falls and this will have this is automatically false because this was false already
04:04But this is true because it's 12
04:07Contrary to that if I put this into a brown bracket and I just say hey if either one of these is true and
04:13This is true only then do it and if we run our application again and refresh and go ahead
04:19Oh and I have your little type because I didn't close my bracket
04:23My second bracket then is so you have to always close everything that you open
04:28Save back to our browser click on refresh
04:32And if we go again and try to do our 12 with the false and animation
04:37It's not going to animate the internal part
04:39The only way is going to animate it is if we set true or do the default which is true as well
04:45all right, so that's the that's the end and that's the or and
04:50that's really all you have to know about these two and you could find a lot of different combinations and they can make your if
04:56statements a lot more streamlined and
04:58much easier in
05:00The next lesson what I want to do is I want to talk about ternary operators
05:05It's a really complicated construct for if conditions
05:09I personally love them a lot of people recommend not to use them, but I love them
05:14So I do use them, so I want you to know about them
05:17They're a little bit complicated, but complicated and geeky is good
05:20So see you in the next lesson when we talk about ternary operators, which will be our last topic about
05:27conditionals
