02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

if and else

We've seen conditionals throughout our learning but we are stopping to understand what this is for a moment.

Video Transcript

00:00We've covered if statements already previously, but we haven't really dug too deep into them
00:05And I want to take a break from objects for a second
00:07Let's talk a little bit about these if statements so basically and we're not going to delve too deeply into if statements
00:13We're kind of like wrapping it as we go. We're using it as we go
00:16So what I want to do is I want to compare and I want to see if a certain date is bigger or smaller
00:21Than another one. So let's say if now is
00:25greater than late date is
00:28Is now greater than late date? No in four days
00:31It's gonna be so but let's see if it works. So let's see if our logic
00:35I don't think it will work, but you never know we're gonna try it out
00:37So we're gonna check here and see and we're gonna alert not trace alert
00:43Now is
00:45later than before and if I refresh this and I run my application we shouldn't be getting our
00:55Alert and that's a good method a good thing because that means that our if statement is working now
01:00if I check our else a little less statement
01:05now is
01:07still in the discount
01:10Now it's still in the discount time and now it's still in the discount time now
01:17Because we don't know
01:19Why this is working? We're basically comparing between two different objects and we're asking if it's bigger or smaller
01:24One good way of avoiding this confusion of not making sure of why is it working or maybe it's not gonna work in different types of
01:31browsers a good way to approach is to approach our a specific millisecond in time and to get that specific millisecond in time
01:39And I want to show this to you guys. So end girls. Let me just comment this out just for a second here
01:44Oh, by the way, I put my alert by mistake outside of the else. So let's push it right in there
01:51It's still the same would still do the same thing currently, but if our now would be actually right then we would get two alerts
01:59alright, so
02:00what I want to do right now is I want to find inside of my inside of one of the
02:05Objects instead of one of the properties of our object is to get basically saying that would give me our
02:11Milliseconds and to do that doesn't really make a lot of sense milliseconds is gonna give us our current milliseconds
02:15But if we try get time you're gonna see that we're gonna get this enormously huge different number
02:20This enormously huge number is basically the amount of seconds that pass since
02:26January 1st
02:281970 I believe
02:30This number is is now now we're dealing with numbers, which is something that's easier to comprehend
02:35So if we're working with numbers
02:37Although we're getting this really really big number and we make sure that way that doesn't matter what browser we're running
02:42We should be getting the amount of milliseconds and then we could compare the amount of milliseconds that
02:47Has passed already to the amount of milliseconds that we wish that will be
02:53Getting to all right. Now if we run this application one more time, we're gonna see that now is still in discount time, which is great
03:01so
03:02Now that we got this sorted out. We know that in this place if we were true
03:08We would want to set our we would want to set our
03:11All the rest to being dimmed out and we want to set and basically leave the third one to basically not be dimmed out
03:21Contrary this place. We still don't know yet which one is the right one, but we do know that
03:27When we're in here, we want what do we want to do?
03:30We want to make sure that the early bird and on time gets faded out. So now before we get that
03:36Rolling what I want to do is I want to make sure that this if statement comes true
03:40No matter what to do that. I'm just gonna type your if true
03:43or
03:44Now for this case, basically what this will do is it's gonna make sure that this if statement will always be true
03:50So while we're testing we'll be able to see it so we could see that our our function here our alert function
03:56That's being called is being called because basically we're saying if it's true and if it's true that it is true
04:01So if it's true or whatever it's gonna be after that, it's always gonna be true. So it's always gonna accept it

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!