Earlier we saw how we can use an IF statement to run cold based on a condition being true and how we
can add in Else block to run cold if the condition is FALSE.
We can add more conditions to this by using El seph.
This is a combination of else and if and allows us to extend an IF statement to include other conditions.
If the first condition is FALSE.
Let's look at an example here.
We're conditionally executing code based on the hour of the day.
Stored in this variable.
This will print out.
Good morning.
If the hour is less than 12.
And good afternoon otherwise with the hour sets to 11.
If we run this in the browser it says good morning.
If we change the hour to 14 for example using the 24 hour clock.
Then in the browser it says.
Good afternoon.
Let's extend this to have some more conditions.
We'll leave the first one if the hour is less than 12.
We say good morning.
But then let's add an L elusive for the afternoon for when the hour is less than 18.
Then let's add another for the evening.
If the hour is less than 22.
And then finally the else which will be run.
If all these conditions are false.
Let's set the hour to 11 and then run this code to see what happens.
We see.
Good morning.
If we change the hour to 20 for example and then run the cold again in the browser we see.
Good evening.
What happens is each condition is checked in turn if the first one is false then the next one is checked.
And so on when one is true that block of code is executed and only that block.
If none of the conditions are true then the else block is executed.
You can have as many L sips as you like and the else is optional.