This is challenge number three, we're building hello, greeter, so first we have to set a default
time so you can set up a variable and set any time you want and then depending on the time, we're going
to output a message.
So, for example, in the morning we could put out good morning.
So depending on what the time reads, we want to output a different message in the console and then
we can manually adjust the variable value of the time and have a bunch of different messages being output.
So here's an example of the code so you can pause the video work through this example and I'll show
you the solution coming up.
So first of all, we need to set a time so we can set this time to be whatever we want.
So let's start out with 9:00 a.m. We're going to do a 24 hour clock in this case, and then we're going
to declare variable output so that we can use that in order to output that information into the console
and console.
Log that out and we're going to put the statement in the middle there.
So for now, when we declare, we see that it's just undefined.
So let's add in our condition.
So checking to see the value of my time.
And if it's under 11:00 a.m., then we can set a value for output to be equal to good morning.
And else we can say that I'm sleeping.
So we get good morning.
And of course, obviously, if we adjust this, then we're going to get a different output.
So let's add in some additional else statements are going to use or else if in order to add those in
so we can do another one or else if and have another condition in there.
And this one is going to use the logical operator because we're going to be checking the Y time and
we're checking to see if it's greater than or equal to 11.
And we also want to make sure that my time is less than or equal to whatever whatever the next interval
is.
So this is going to be 17 where we're going to output a value for output of good afternoon.
And in this case, we want to use that and to make sure that both of these are coming back as true.
So save and try that.
So first it comes back as sleeping.
So let's adjust that so that we land our time to 3:00 p.m. and we see that we get.
Good afternoon.
Let's do a few more, a few more in so another EL statement, I just did a quick clean up their.
So next interval is we're checking to see if it's larger than 17, so it is going to make sure that
we are accounting for everything.
So this is less than or equal to 17.
So that's why this one isn't equal to 17, because there would be no point.
And of course, this one, if it was 17, that one would already equate to being true.
So that's why we're leaving out the other equal sign, their.
And then we're also checking to see if my time is less than twenty three and if it is, then we're going
to output.
Good evening.
Let's try that again.
So good afternoon and let's try 22 o'clock.
And that's good evening.
So you can play around with this and add in as many options as you can, always using the conditions
to make sure that you're getting the right interval between the times so that you can output the correct
message depending on whatever the time value is.
Next, I'm going to show you another way to do this and an even easier way using the switch statement.
That's coming next.