WEBVTT

0
00:00.240 --> 00:02.820
Now we're almost there. When we hit start,

1
00:02.880 --> 00:07.880
our countdown works and it starts counting down from however minutes we tell it

2
00:08.550 --> 00:11.130
to. Here's a challenge for you.

3
00:11.700 --> 00:16.700
We know that the Pomodoro technique requires us to work for 25 minutes and then

4
00:18.180 --> 00:21.300
after 25 minutes to take a short break,

5
00:21.780 --> 00:26.780
and then it goes back to 25 and this repeats until we've done four sets of 25

6
00:27.690 --> 00:30.390
minutes, and then we get a long break.

7
00:31.050 --> 00:36.050
So I want you to have a think about how you could create a variable called reps,

8
00:36.570 --> 00:41.010
which is going to be a global variable, and you can access it inside

9
00:41.040 --> 00:46.040
start_timer by tapping into this global reps. Now using the modulo or some other

10
00:48.180 --> 00:52.890
sort of mechanism that you can think of see if you can figure out how to get our

11
00:52.890 --> 00:57.840
countdown timer to count down a different number of minutes.

12
00:58.440 --> 01:02.820
For example, we would start out with work_seconds

13
01:03.120 --> 01:07.410
which is going to be the work in minutes times 60,

14
01:08.310 --> 01:11.910
and then we have our short_break_sec

15
01:14.040 --> 01:16.620
and our long break seconds.

16
01:19.530 --> 01:22.530
Now, how can we call this countdown timer

17
01:22.530 --> 01:27.530
so that if it's the first third,

18
01:30.180 --> 01:31.013
fifth,

19
01:31.830 --> 01:35.550
seventh, rep that we're actually doing our countdown,

20
01:35.910 --> 01:40.710
then we want this countdown to do our 25 minutes in terms of work seconds.

21
01:41.400 --> 01:44.550
But on the other hand, if it is, um,

22
01:44.610 --> 01:47.460
the eighth rep,

23
01:47.490 --> 01:52.260
then we want the countdown to work on our long break seconds.

24
01:52.920 --> 01:57.920
But if it's the second or fourth or sixth rep then it should count down to our

25
02:03.720 --> 02:05.460
short break seconds.

26
02:06.900 --> 02:11.520
Essentially what we're trying to achieve is for our countdown timer to do 25

27
02:11.520 --> 02:14.580
minutes, then 5 minutes, then 25, 5,

28
02:15.030 --> 02:18.000
and until we've done four sets of 25,

29
02:18.330 --> 02:21.120
then do we get a 20 minute break.

30
02:21.570 --> 02:25.650
So have a think about what you've done before using the modulo and see if you

31
02:25.650 --> 02:29.160
can figure out how to get this to work in your code.

32
02:29.790 --> 02:32.700
Pause the video and see if you can complete this challenge.

33
02:35.220 --> 02:35.610
All right.

34
02:35.610 --> 02:40.610
So what we want to do is first when we start the timer to increase the reps.

35
02:41.790 --> 02:44.130
So we're going to increase it by one.

36
02:44.580 --> 02:49.580
So now it starts out at the first rep or the first repetition.

37
02:50.610 --> 02:52.500
Now on this first repetition,

38
02:52.590 --> 02:56.760
it's going to need to run this particular line of code.

39
02:57.420 --> 02:59.650
And then when it gets to the second repetition, 

40
02:59.650 --> 03:02.290
it needs to run this line of code. And finally,

41
03:02.290 --> 03:06.520
when it gets to the eighth repetition then it needs to run this line of code.

42
03:07.030 --> 03:11.410
So we can actually use a if statement to check for all of these things.

43
03:11.890 --> 03:16.890
So here we can check to see if the reps modulo by 8 is equal to zero.

44
03:19.990 --> 03:23.170
If the number of reps divided by 8 has no remainder,

45
03:23.440 --> 03:27.130
then that means it's actually the time for a long break.

46
03:28.270 --> 03:29.740
Now, Elif though,

47
03:29.740 --> 03:33.850
or else if the reps is actually even,

48
03:33.880 --> 03:37.810
so if modulo 2 is equal to zero, then in this case

49
03:37.870 --> 03:40.720
it should be time for a short break.

50
03:42.910 --> 03:44.140
And finally,

51
03:44.200 --> 03:48.340
if it's none of those conditions and we have an else statement,

52
03:48.760 --> 03:52.450
then it's just a normal work time.

53
03:53.530 --> 03:55.840
Now we might think that's all that's required,

54
03:55.960 --> 03:59.080
but as usual we have to test it to be sure.

55
03:59.620 --> 04:04.620
So let's go ahead and change our work minute down to one minute so that we can

56
04:04.960 --> 04:09.640
run it and have a reasonable chance of seeing when it actually finally reaches

57
04:09.670 --> 04:10.503
zero.

58
04:10.930 --> 04:14.740
Once our timer counter goes down to zero,

59
04:15.130 --> 04:19.180
we would expect it to go to a five minute break,

60
04:19.540 --> 04:22.600
but it doesn't. It actually just stops.

61
04:23.260 --> 04:28.260
And this is why we need to test our code and test our programs as frequently as

62
04:29.170 --> 04:33.400
we write code so that we can catch these bugs in terms of our logic.

63
04:33.970 --> 04:35.890
So what's happening here? Well,

64
04:35.920 --> 04:39.880
basically it's counting down to

65
04:39.880 --> 04:42.820
the number of seconds that we told it to count down to.

66
04:43.330 --> 04:47.080
And then once it's done that, well, that's kind of the end.

67
04:47.200 --> 04:52.200
There's no other way of triggering start timer unless we press the button.

68
04:53.140 --> 04:58.140
So what we actually need to do is to add a else statement here and catch when the

69
05:01.270 --> 05:02.770
count goes to zero,

70
05:03.190 --> 05:07.540
because it's in that moment that we want to actually call start timer

71
05:07.780 --> 05:08.613
once again.

72
05:09.130 --> 05:13.600
And this time it's going to increase the reps and figure out which countdown we

73
05:13.600 --> 05:14.740
actually need to go to.

74
05:15.430 --> 05:19.000
So if we run this code again and I fast forward through the timer,

75
05:19.450 --> 05:22.360
you can see that now, once it hits zero,

76
05:23.260 --> 05:27.760
it's going to go straight to our five minute break and it continues the timer.

77
05:28.660 --> 05:31.870
Now, as the user though, it's quite hard to tell whether

78
05:31.870 --> 05:36.870
if I'm in a work section or if I'm in a break section and what's actually

79
05:37.180 --> 05:38.013
going on.

80
05:38.260 --> 05:42.910
So we should improve the user experience by changing this title from saying

81
05:42.940 --> 05:46.300
timer to whatever it is that the user should be doing.

82
05:46.900 --> 05:51.880
So if they are in this long break countdown then it should say

83
05:51.910 --> 05:55.360
break, if they're in a short break section it should say break,

84
05:55.420 --> 05:58.250
and if they're in the work section then it should say work.

85
05:58.760 --> 06:02.450
So the label that we need to change is this title label.

86
06:02.960 --> 06:07.040
And I also want to change the color, the foreground color,

87
06:07.400 --> 06:12.170
so that when it's work, it's green, when its a short break it's pink,

88
06:12.500 --> 06:14.930
when it was a long break it's red. So of course,

89
06:14.930 --> 06:17.330
I'm referring to these constants over here.

90
06:18.050 --> 06:22.580
See if you can complete this as a challenge and get that label to change

91
06:22.640 --> 06:25.730
to display to the user, what they should be doing each time.

92
06:26.390 --> 06:31.280
Pause the video and complete this challenge. Okay.

93
06:31.310 --> 06:33.110
So when they're on a long break,

94
06:33.140 --> 06:38.140
we're going to get our title label to configure it and change the text to say

95
06:41.120 --> 06:41.953
break.

96
06:42.590 --> 06:46.940
And we're also going to configure the foreground color at the same time

97
06:47.300 --> 06:48.650
and we're going to make this

98
06:48.680 --> 06:52.670
the red color. Now for the next one,

99
06:52.670 --> 06:57.320
which is the short break, it's also going to read break, but in this case,

100
06:57.380 --> 07:02.000
the foreground color is going to be pink. And finally,

101
07:02.330 --> 07:03.680
when they should be working,

102
07:03.740 --> 07:08.720
the foreground color is going to be green and the label is going to read work.

103
07:09.350 --> 07:14.210
So now when it's during a work session, it will say work.

104
07:14.630 --> 07:17.030
And when it switches to the break time,

105
07:18.170 --> 07:22.340
then it's going to say break. And because this is pink,

106
07:22.370 --> 07:26.000
this is, of course, the short break where we can also see that we've got five

107
07:26.000 --> 07:29.180
minutes and counting. And when it gets to the long break

108
07:29.300 --> 07:31.010
after four sessions of work,

109
07:31.040 --> 07:35.720
then the text would be red and the countdown would show 20 minutes.

110
07:36.980 --> 07:40.880
We're pretty much almost there. There's just a couple of loose ends to tie off.

111
07:41.240 --> 07:46.240
One is to change this part so that we actually get a checkmark for every

112
07:47.150 --> 07:52.150
successful work session we complete, and also to make sure that our reset button

113
07:52.460 --> 07:56.690
works so that when we click on it, the timer stops and goes back to zero.

114
07:57.470 --> 08:00.470
So for all of that and more, I'll see you in the next lesson.