Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,090 --> 00:00:02,570
All right so let's try to tackle this challenge.
2
00:00:02,610 --> 00:00:03,990
Step by step.
3
00:00:03,990 --> 00:00:10,850
Now if we look at the flow chart the first question we ask is Is it cleanly divisible by four.
4
00:00:10,860 --> 00:00:13,470
If no then it's definitely not a leap year.
5
00:00:13,470 --> 00:00:16,340
If yes then we have to ask more questions.
6
00:00:16,410 --> 00:00:19,110
So how would we write this in terms of code.
7
00:00:19,650 --> 00:00:27,390
Well we'd probably use an if statement to check if the year that were being passed in here is cleanly
8
00:00:27,390 --> 00:00:28,600
divisible by four.
9
00:00:29,220 --> 00:00:35,250
And remember that on a previous lesson which I linked to here we learned about the modulo operator which
10
00:00:35,250 --> 00:00:37,680
gives you the remainder of a division.
11
00:00:37,680 --> 00:00:46,260
So if the year modulo four is equal to zero namely if there is no remainder when you divide the year
12
00:00:46,260 --> 00:00:47,320
by four.
13
00:00:47,330 --> 00:00:50,130
Well in that case then it's likely to be a leap year.
14
00:00:50,700 --> 00:00:56,790
But if it's not even divisible by four then it's definitely not a leap year.
15
00:00:56,790 --> 00:01:00,540
So here we could simply return not leap year.
16
00:01:01,140 --> 00:01:03,350
So any year that is not divisible by four.
17
00:01:03,360 --> 00:01:09,750
That is definitely not a leap year but if it is divisible by four we still have to check is it cleanly
18
00:01:09,750 --> 00:01:11,860
divisible by 100.
19
00:01:12,030 --> 00:01:14,700
Because if no then it's definitely a leap year.
20
00:01:15,000 --> 00:01:17,670
But if yes then we have to check further.
21
00:01:17,670 --> 00:01:24,240
So the best way to represent that logic is to create another if statement inside this if statement.
22
00:01:24,260 --> 00:01:26,320
So it's already divisible by four.
23
00:01:26,460 --> 00:01:29,720
But we have to check whether if it's divisible by 100.
24
00:01:29,790 --> 00:01:38,010
So if the year modulo 100 is equal to zero Well then we have to make some further checks.
25
00:01:38,100 --> 00:01:42,120
But if it's not then it's definitely a leap year.
26
00:01:42,150 --> 00:01:45,250
So we can return leap year.
27
00:01:45,270 --> 00:01:51,210
Now finally we're in the homestretch and we have to ask ourselves the last question is it cleanly divisible
28
00:01:51,210 --> 00:01:52,710
by 400.
29
00:01:52,740 --> 00:01:54,600
If no then it's not a leap year.
30
00:01:54,600 --> 00:01:56,320
If yes then it is a leap year.
31
00:01:56,820 --> 00:02:04,470
So inside this if statement we're going to ask ourselves one further question if the year is divisible
32
00:02:04,470 --> 00:02:06,240
by 400.
33
00:02:06,480 --> 00:02:08,250
And that has no remainder.
34
00:02:08,580 --> 00:02:11,120
Well then it's definitely a leap year.
35
00:02:11,160 --> 00:02:16,960
And if that's not true then it's definitely not a leap year.
36
00:02:17,060 --> 00:02:25,340
So this is the logic that we saw in the flowchart mapped out with javascript code and going from these
37
00:02:25,340 --> 00:02:28,360
words to code is actually quite a big jump.
38
00:02:28,730 --> 00:02:35,930
But going via that middle ground that flowchart makes it so much easier to actually map out the logic
39
00:02:36,260 --> 00:02:38,610
and then converting it into code.
40
00:02:38,630 --> 00:02:43,220
So hope you enjoy that challenge and you managed to get it right and at least if you didn't you saw
41
00:02:43,220 --> 00:02:50,480
how you can use flow charts to simplify and clarify your own idea of the logic because at the end of
42
00:02:50,480 --> 00:02:52,190
the day the code is easy.
43
00:02:52,280 --> 00:02:55,020
But the logic is the path that you've got to get right first.
44
00:02:55,190 --> 00:02:59,480
So now if we check our solution then everything should pass.
3992
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.