Okay, we've covered if statements. And we've determined that if the condition is met, if it's true, then it executes the first bit of code after the if statement. If it's not, if it's false executes the code that follows the else portion. Well, what if there's more than two possibilities that we want to be able to handle? Well, we can do that with elsif. So we can string if statements together using else F. Let's take a look at a scenario where that might be helpful.
I'm going to jump to sublime for this exercise. And here's what we're going to do. Let me increase the text size so it's easier, easier to see. We're going to use the data object and print out the day of the week, if you remember from the data object when we asked for the day of the week. returns a numbers zero to six. It's zero base zero is Sunday.
One is Monday, and so on. So let's use the if statement to be able to print out the actual day of the week. So first let's create a variable date and set it equal to new date, we create our data object and put it in the date variable. Now let's go ahead and do a second variable day and set that equal to date dot whoops, get day, the method from the date object that returns the day of the week. Okay, so that will now have a number in it. So now you can use if statements to determine what number it is and thereby print out the day of the week.
So if day strict equality equals zero Then we're going to print out console dot log. Today is, whoops, Sunday. So that will be our first console dot log statement. Now this so far the if statement is very similar to things we've done in the past. Normally we would do an lt at this point. But in this situation, we have another six days to contend with.
So how do we do that? Well, we can, we can add additional if statements so we do else if day equals one. Now we test for that case. Console dot log. Today is Monday. Okay.
So that takes care of this the second day of the week, and I just noticed up here I misspelled console dot log. Now We will continue to do that. So I'm going to copy this portion of my code. And I'm just going to paste it for Tuesday, Wednesday, Thursday, Friday, Saturday. And then I just need to go need to come in here and change these numbers. And then I need to change the days of the week.
So two would be Tuesday, three Wednesday, for Thursday. Five is Friday. And then six is Saturday. All right, so now we have a series of if statements using eltz. If that would allow us to determine what day of the week it is. I'm going to say this and let's go ahead and see how it works.
Go to my HTML I'm just going to copy the file path and then we'll jump to the browser. And I'll paste that in. Open the console to see what was returned. And it says Today is Tuesday. And you'll just have to trust me. But today is Tuesday.
So that worked for us. Now in the next movie, we're going to take a look at the switch statement to accomplish this same thing. It's another type of conditional that can be used to accomplish to accomplish what we just did here where you have more than one possibility. So we'll take a look at that in the next movie.