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

Adding Hours

We need to count hours so lets change our code to make that happen.

Video Transcript

00:00So, the next step now that we got our visuals more or less ready is we want to set up, we
00:04want to go to our, we want to start changing our timeout messages and trying to change
00:09it to the format, to a format that is closer to this.
00:13All right?
00:14So, the next step to do that, what I'm going to do is I'm going to go into my timeout
00:16display which is my main class that I'm working with.
00:20And if I just drag myself down to the area where I'm actually changing the copy, we can
00:25see that first of all I'm changing my copy and I'm only doing the minutes and seconds
00:30which isn't good enough because we're going to need those to get hours and we're going
00:33to need to get days.
00:34So, we're going to have to go into our timeout and actually add those functions.
00:39So, again, I'm going to scroll down until we reach our seconds panel and minutes panel.
00:47We could copy our minutes panel and we could do the same thing in our function here instead
00:53of get minutes, we're going to get hours.
00:57And how many hours are there?
00:58Now that the minutes wouldn't be accurate anymore, right, because we know that there
01:02are hours, we have to account for the fact that there are hours now.
01:06So, let's first fix hours before we go down to our minutes and figure our minutes out.
01:12Now that we know that we need to get our hours is we want to take the total seconds
01:16and this time around we want to divide it by 60 times 60 which will give us the amount
01:20of hours.
01:21Now, instead of redoing this calculation each and every time, such as 60 is not a calculation
01:27but instead of doing 60 times 60 every time, well, obviously it makes more sense to calculate
01:33in our head and type 360 but if that sounds complicated, we could just go and create
01:38a new variable just as a reference for us to use.
01:41We're going to create a private variable which we're going to call seconds and hour
01:50which will be a type of integer and we could set it already as soon as we're creating
01:55it once.
01:56It's actually is worth 60 times 60 which gives us the amount of seconds in an hour.
02:03Now that we have the variable seconds in an hour, we could just divide our get hours
02:09by that value and that would give us, but what would that give us?
02:13That would give us the amount of hours with some extras, right, but we're getting rid
02:20of those extras by setting it back to end, alright.
02:24Now, the next step that we want to do is now that we got our hours is we want to get
02:28our minutes.
02:29Now, to get our minutes would be a very simple scenario as well where we, instead of we're
02:34going to have to first get rid of our amount of hours, it only takes, basically we're going
02:39to get our hours and after we get our hours, we're going to have the value that's actually
02:45left over.
02:47So in other words, we're going to have to ask for our mold or the left over after
02:52we get rid of hours and then divide that left over.
02:57Now, things are getting more complicated.
03:00So as we're getting rid of the hours, now if we add days, will that change our minutes?
03:06No, because after we got rid of hours, it will get rid of the days as well, right.
03:10That's not true to the case of get hours, so we're going to have to change get hours
03:13again as we get closer to them.
03:15So let's change first minutes to make sure that minutes will work now as well.
03:19So to make minutes work, I'm going to have to divide, I'm going to have to get the mold
03:23value of this division, right.
03:26So instead of doing a division, I'm just going to put it in a bracket to make it easier
03:29to see.
03:30Instead of dividing it, I'm going to get the mold you and that mold will return me a
03:35value that could be maximum of 360 seconds and those 360 seconds or 60 times 60 more
03:43accurately, which is a little bit more than 360 seconds, we'll actually, we'll divide
03:49that by 60, giving us the amount of minutes.
03:53Let's just save this out for a minute and just test our application and see if we could
03:56just get, if our application works for hours, minutes and seconds.
04:01So let's just do that.
04:02All we have to change in our display itself is just add into our display.
04:08Just grab this and add it in the beginning and add a little plus right here and change
04:14from get minutes to get hours, we could save that.
04:21And don't worry about that.
04:22It's getting, it's turning blue, it's not reserved words, it's just these functions
04:27exist on different classes in flash.
04:29So it's just giving us some hints that aren't really that relevant to us right now.
04:35So if we run our application just one more time, in theory, it should be running already
04:39and we should be getting that structure.
04:42Now all we have to do to test it out and actually see it in action and see if it
04:45really works is if we change that bigger value.
04:48So let's take 60 seconds times 60 which will give us one minute, one hour and then we
04:56have your one hour and let's just add three to it.
04:59So we're going to have an hour and three seconds and if we run it now we should be
05:03getting one hour and after those three seconds pass it should switch it to 59 and it should
05:10continue going down.

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!