Now we're almost there. When we hit start,
our countdown works and it starts counting down from however minutes we tell it
to. Here's a challenge for you.
We know that the Pomodoro technique requires us to work for 25 minutes and then
after 25 minutes to take a short break,
and then it goes back to 25 and this repeats until we've done four sets of 25
minutes, and then we get a long break.
So I want you to have a think about how you could create a variable called reps,
which is going to be a global variable, and you can access it inside
start_timer by tapping into this global reps. Now using the modulo or some other
sort of mechanism that you can think of see if you can figure out how to get our
countdown timer to count down a different number of minutes.
For example, we would start out with work_seconds
which is going to be the work in minutes times 60,
and then we have our short_break_sec
and our long break seconds.
Now, how can we call this countdown timer
so that if it's the first third,
fifth,
seventh, rep that we're actually doing our countdown,
then we want this countdown to do our 25 minutes in terms of work seconds.
But on the other hand, if it is, um,
the eighth rep,
then we want the countdown to work on our long break seconds.
But if it's the second or fourth or sixth rep then it should count down to our
short break seconds.
Essentially what we're trying to achieve is for our countdown timer to do 25
minutes, then 5 minutes, then 25, 5,
and until we've done four sets of 25,
then do we get a 20 minute break.
So have a think about what you've done before using the modulo and see if you
can figure out how to get this to work in your code.
Pause the video and see if you can complete this challenge.
All right.
So what we want to do is first when we start the timer to increase the reps.
So we're going to increase it by one.
So now it starts out at the first rep or the first repetition.
Now on this first repetition,
it's going to need to run this particular line of code.
And then when it gets to the second repetition,
it needs to run this line of code. And finally,
when it gets to the eighth repetition then it needs to run this line of code.
So we can actually use a if statement to check for all of these things.
So here we can check to see if the reps modulo by 8 is equal to zero.
If the number of reps divided by 8 has no remainder,
then that means it's actually the time for a long break.
Now, Elif though,
or else if the reps is actually even,
so if modulo 2 is equal to zero, then in this case
it should be time for a short break.
And finally,
if it's none of those conditions and we have an else statement,
then it's just a normal work time.
Now we might think that's all that's required,
but as usual we have to test it to be sure.
So let's go ahead and change our work minute down to one minute so that we can
run it and have a reasonable chance of seeing when it actually finally reaches
zero.
Once our timer counter goes down to zero,
we would expect it to go to a five minute break,
but it doesn't. It actually just stops.
And this is why we need to test our code and test our programs as frequently as
we write code so that we can catch these bugs in terms of our logic.
So what's happening here? Well,
basically it's counting down to
the number of seconds that we told it to count down to.
And then once it's done that, well, that's kind of the end.
There's no other way of triggering start timer unless we press the button.
So what we actually need to do is to add a else statement here and catch when the
count goes to zero,
because it's in that moment that we want to actually call start timer
once again.
And this time it's going to increase the reps and figure out which countdown we
actually need to go to.
So if we run this code again and I fast forward through the timer,
you can see that now, once it hits zero,
it's going to go straight to our five minute break and it continues the timer.
Now, as the user though, it's quite hard to tell whether
if I'm in a work section or if I'm in a break section and what's actually
going on.
So we should improve the user experience by changing this title from saying
timer to whatever it is that the user should be doing.
So if they are in this long break countdown then it should say
break, if they're in a short break section it should say break,
and if they're in the work section then it should say work.
So the label that we need to change is this title label.
And I also want to change the color, the foreground color,
so that when it's work, it's green, when its a short break it's pink,
when it was a long break it's red. So of course,
I'm referring to these constants over here.
See if you can complete this as a challenge and get that label to change
to display to the user, what they should be doing each time.
Pause the video and complete this challenge. Okay.
So when they're on a long break,
we're going to get our title label to configure it and change the text to say
break.
And we're also going to configure the foreground color at the same time
and we're going to make this
the red color. Now for the next one,
which is the short break, it's also going to read break, but in this case,
the foreground color is going to be pink. And finally,
when they should be working,
the foreground color is going to be green and the label is going to read work.
So now when it's during a work session, it will say work.
And when it switches to the break time,
then it's going to say break. And because this is pink,
this is, of course, the short break where we can also see that we've got five
minutes and counting. And when it gets to the long break
after four sessions of work,
then the text would be red and the countdown would show 20 minutes.
We're pretty much almost there. There's just a couple of loose ends to tie off.
One is to change this part so that we actually get a checkmark for every
successful work session we complete, and also to make sure that our reset button
works so that when we click on it, the timer stops and goes back to zero.
So for all of that and more, I'll see you in the next lesson.