1
00:00:00,240 --> 00:00:02,820
Now we're almost there. When we hit start,

2
00:00:02,880 --> 00:00:07,880
our countdown works and it starts counting down from however minutes we tell it

3
00:00:08,550 --> 00:00:11,130
to. Here's a challenge for you.

4
00:00:11,700 --> 00:00:16,700
We know that the Pomodoro technique requires us to work for 25 minutes and then

5
00:00:18,180 --> 00:00:21,300
after 25 minutes to take a short break,

6
00:00:21,780 --> 00:00:26,780
and then it goes back to 25 and this repeats until we've done four sets of 25

7
00:00:27,690 --> 00:00:30,390
minutes, and then we get a long break.

8
00:00:31,050 --> 00:00:36,050
So I want you to have a think about how you could create a variable called reps,

9
00:00:36,570 --> 00:00:41,010
which is going to be a global variable, and you can access it inside

10
00:00:41,040 --> 00:00:46,040
start_timer by tapping into this global reps. Now using the modulo or some other

11
00:00:48,180 --> 00:00:52,890
sort of mechanism that you can think of see if you can figure out how to get our

12
00:00:52,890 --> 00:00:57,840
countdown timer to count down a different number of minutes.

13
00:00:58,440 --> 00:01:02,820
For example, we would start out with work_seconds

14
00:01:03,120 --> 00:01:07,410
which is going to be the work in minutes times 60,

15
00:01:08,310 --> 00:01:11,910
and then we have our short_break_sec

16
00:01:14,040 --> 00:01:16,620
and our long break seconds.

17
00:01:19,530 --> 00:01:22,530
Now, how can we call this countdown timer

18
00:01:22,530 --> 00:01:27,530
so that if it's the first third,

19
00:01:30,180 --> 00:01:31,013
fifth,

20
00:01:31,830 --> 00:01:35,550
seventh, rep that we're actually doing our countdown,

21
00:01:35,910 --> 00:01:40,710
then we want this countdown to do our 25 minutes in terms of work seconds.

22
00:01:41,400 --> 00:01:44,550
But on the other hand, if it is, um,

23
00:01:44,610 --> 00:01:47,460
the eighth rep,

24
00:01:47,490 --> 00:01:52,260
then we want the countdown to work on our long break seconds.

25
00:01:52,920 --> 00:01:57,920
But if it's the second or fourth or sixth rep then it should count down to our

26
00:02:03,720 --> 00:02:05,460
short break seconds.

27
00:02:06,900 --> 00:02:11,520
Essentially what we're trying to achieve is for our countdown timer to do 25

28
00:02:11,520 --> 00:02:14,580
minutes, then 5 minutes, then 25, 5,

29
00:02:15,030 --> 00:02:18,000
and until we've done four sets of 25,

30
00:02:18,330 --> 00:02:21,120
then do we get a 20 minute break.

31
00:02:21,570 --> 00:02:25,650
So have a think about what you've done before using the modulo and see if you

32
00:02:25,650 --> 00:02:29,160
can figure out how to get this to work in your code.

33
00:02:29,790 --> 00:02:32,700
Pause the video and see if you can complete this challenge.

34
00:02:35,220 --> 00:02:35,610
All right.

35
00:02:35,610 --> 00:02:40,610
So what we want to do is first when we start the timer to increase the reps.

36
00:02:41,790 --> 00:02:44,130
So we're going to increase it by one.

37
00:02:44,580 --> 00:02:49,580
So now it starts out at the first rep or the first repetition.

38
00:02:50,610 --> 00:02:52,500
Now on this first repetition,

39
00:02:52,590 --> 00:02:56,760
it's going to need to run this particular line of code.

40
00:02:57,420 --> 00:02:59,650
And then when it gets to the second repetition, 

41
00:02:59,650 --> 00:03:02,290
it needs to run this line of code. And finally,

42
00:03:02,290 --> 00:03:06,520
when it gets to the eighth repetition then it needs to run this line of code.

43
00:03:07,030 --> 00:03:11,410
So we can actually use a if statement to check for all of these things.

44
00:03:11,890 --> 00:03:16,890
So here we can check to see if the reps modulo by 8 is equal to zero.

45
00:03:19,990 --> 00:03:23,170
If the number of reps divided by 8 has no remainder,

46
00:03:23,440 --> 00:03:27,130
then that means it's actually the time for a long break.

47
00:03:28,270 --> 00:03:29,740
Now, Elif though,

48
00:03:29,740 --> 00:03:33,850
or else if the reps is actually even,

49
00:03:33,880 --> 00:03:37,810
so if modulo 2 is equal to zero, then in this case

50
00:03:37,870 --> 00:03:40,720
it should be time for a short break.

51
00:03:42,910 --> 00:03:44,140
And finally,

52
00:03:44,200 --> 00:03:48,340
if it's none of those conditions and we have an else statement,

53
00:03:48,760 --> 00:03:52,450
then it's just a normal work time.

54
00:03:53,530 --> 00:03:55,840
Now we might think that's all that's required,

55
00:03:55,960 --> 00:03:59,080
but as usual we have to test it to be sure.

56
00:03:59,620 --> 00:04:04,620
So let's go ahead and change our work minute down to one minute so that we can

57
00:04:04,960 --> 00:04:09,640
run it and have a reasonable chance of seeing when it actually finally reaches

58
00:04:09,670 --> 00:04:10,503
zero.

59
00:04:10,930 --> 00:04:14,740
Once our timer counter goes down to zero,

60
00:04:15,130 --> 00:04:19,180
we would expect it to go to a five minute break,

61
00:04:19,540 --> 00:04:22,600
but it doesn't. It actually just stops.

62
00:04:23,260 --> 00:04:28,260
And this is why we need to test our code and test our programs as frequently as

63
00:04:29,170 --> 00:04:33,400
we write code so that we can catch these bugs in terms of our logic.

64
00:04:33,970 --> 00:04:35,890
So what's happening here? Well,

65
00:04:35,920 --> 00:04:39,880
basically it's counting down to

66
00:04:39,880 --> 00:04:42,820
the number of seconds that we told it to count down to.

67
00:04:43,330 --> 00:04:47,080
And then once it's done that, well, that's kind of the end.

68
00:04:47,200 --> 00:04:52,200
There's no other way of triggering start timer unless we press the button.

69
00:04:53,140 --> 00:04:58,140
So what we actually need to do is to add a else statement here and catch when the

70
00:05:01,270 --> 00:05:02,770
count goes to zero,

71
00:05:03,190 --> 00:05:07,540
because it's in that moment that we want to actually call start timer

72
00:05:07,780 --> 00:05:08,613
once again.

73
00:05:09,130 --> 00:05:13,600
And this time it's going to increase the reps and figure out which countdown we

74
00:05:13,600 --> 00:05:14,740
actually need to go to.

75
00:05:15,430 --> 00:05:19,000
So if we run this code again and I fast forward through the timer,

76
00:05:19,450 --> 00:05:22,360
you can see that now, once it hits zero,

77
00:05:23,260 --> 00:05:27,760
it's going to go straight to our five minute break and it continues the timer.

78
00:05:28,660 --> 00:05:31,870
Now, as the user though, it's quite hard to tell whether

79
00:05:31,870 --> 00:05:36,870
if I'm in a work section or if I'm in a break section and what's actually

80
00:05:37,180 --> 00:05:38,013
going on.

81
00:05:38,260 --> 00:05:42,910
So we should improve the user experience by changing this title from saying

82
00:05:42,940 --> 00:05:46,300
timer to whatever it is that the user should be doing.

83
00:05:46,900 --> 00:05:51,880
So if they are in this long break countdown then it should say

84
00:05:51,910 --> 00:05:55,360
break, if they're in a short break section it should say break,

85
00:05:55,420 --> 00:05:58,250
and if they're in the work section then it should say work.

86
00:05:58,760 --> 00:06:02,450
So the label that we need to change is this title label.

87
00:06:02,960 --> 00:06:07,040
And I also want to change the color, the foreground color,

88
00:06:07,400 --> 00:06:12,170
so that when it's work, it's green, when its a short break it's pink,

89
00:06:12,500 --> 00:06:14,930
when it was a long break it's red. So of course,

90
00:06:14,930 --> 00:06:17,330
I'm referring to these constants over here.

91
00:06:18,050 --> 00:06:22,580
See if you can complete this as a challenge and get that label to change

92
00:06:22,640 --> 00:06:25,730
to display to the user, what they should be doing each time.

93
00:06:26,390 --> 00:06:31,280
Pause the video and complete this challenge. Okay.

94
00:06:31,310 --> 00:06:33,110
So when they're on a long break,

95
00:06:33,140 --> 00:06:38,140
we're going to get our title label to configure it and change the text to say

96
00:06:41,120 --> 00:06:41,953
break.

97
00:06:42,590 --> 00:06:46,940
And we're also going to configure the foreground color at the same time

98
00:06:47,300 --> 00:06:48,650
and we're going to make this

99
00:06:48,680 --> 00:06:52,670
the red color. Now for the next one,

100
00:06:52,670 --> 00:06:57,320
which is the short break, it's also going to read break, but in this case,

101
00:06:57,380 --> 00:07:02,000
the foreground color is going to be pink. And finally,

102
00:07:02,330 --> 00:07:03,680
when they should be working,

103
00:07:03,740 --> 00:07:08,720
the foreground color is going to be green and the label is going to read work.

104
00:07:09,350 --> 00:07:14,210
So now when it's during a work session, it will say work.

105
00:07:14,630 --> 00:07:17,030
And when it switches to the break time,

106
00:07:18,170 --> 00:07:22,340
then it's going to say break. And because this is pink,

107
00:07:22,370 --> 00:07:26,000
this is, of course, the short break where we can also see that we've got five

108
00:07:26,000 --> 00:07:29,180
minutes and counting. And when it gets to the long break

109
00:07:29,300 --> 00:07:31,010
after four sessions of work,

110
00:07:31,040 --> 00:07:35,720
then the text would be red and the countdown would show 20 minutes.

111
00:07:36,980 --> 00:07:40,880
We're pretty much almost there. There's just a couple of loose ends to tie off.

112
00:07:41,240 --> 00:07:46,240
One is to change this part so that we actually get a checkmark for every

113
00:07:47,150 --> 00:07:52,150
successful work session we complete, and also to make sure that our reset button

114
00:07:52,460 --> 00:07:56,690
works so that when we click on it, the timer stops and goes back to zero.

115
00:07:57,470 --> 00:08:00,470
So for all of that and more, I'll see you in the next lesson.

