‫Welcome back.
‫In this video, I would like to show you my solution to the ternary operator challenge.
‫And of course, use could look differently.
‫So I'd say let's just get started.
‫So the first thing that we will need is a input temperature, then the temperature message as well as
‫the input value.
‫And I'm using string empty here.
‫You could of course just let it be an empty string, but it really opens up other opportunities to work
‫with the string when we do it like this.
‫So what we first of all need to know is the temperature that the user enters and we get the input from
‫the console by using the console that read line.
‫And then we want to validate if the value that the user entered is in fact a valid integer or not.
‫And here we use try parse and we've done that multiple times.
‫So I'm just going to keep it simple here.
‫So just use this boolean to know if it was valid or not.
‫And based on that, we can then go ahead and do the actual paternity operator.
‫So I'm going to use an if statement with an LS statement here to check for the valid integer, but for
‫the actual temperature, I'm going to use a ternary operator.
‫So let's look at this.
‫So what I have here is this if statement if valid integer.
‫So if the input that the user entered is in fact an integer, then this code plug will be executed.
‫And what is going to happen here?
‫And by the way, of course, it's message with one eight.
‫So what I have here is I say input temperature less or equal 15 So this is my statement because here
‫I'm using the ternary operator and you can see it's a multi level ternary operator which can become
‫quite complex.
‫So I'm going to go through it step by step.
‫So this here is basically my condition.
‫So I'm checking, checking is input temperature less or equal?
‫15 Now I'm checking.
‫If that is true then state it is too cold here.
‫So this is.
‫The true case.
‫And then what happens in the false case?
‫In the first case, what I have is another condition.
‫So here I'm checking again.
‫Is the input temperature greater equals 16 and less equal 28.
‫So is it between 16 and to 28 degrees?
‫And we're talking about degrees Celsius here.
‫And then I have another check.
‫So I'm saying if it is true, execute this here.
‫So just say it's cold here.
‫Otherwise the this year I'll run the next code.
‫So in our case we have another check.
‫So here, by the way, this is for the case.
‫It's true.
‫And this is for the case.
‫It's false.
‫And then we have this check in temperature crater 28.
‫If that is the case, print, it is hot here and else an empty string.
‫So because we have all of those other checks here already.
‫So if it's less than 15 and if it's higher than 28 and we have all of the cases in between, then basically
‫this case will never be happening or it will never actually happen.
‫But we still need to maintain the structure.
‫So this is the condition.
‫Then we say it's a ternary operator.
‫Then we say, This is what's going to happen if it's true and this is what's going to happen if it's
‫false.
‫So after the colon each time.
‫So I can.
‫Of course.
‫Have the same structure here again.
‫So I'm saying.
‫True.
‫And I'm saying.
‫False.
‫All right.
‫So this is our pretty long ternary operator with multiple cases in there.
‫But overall, that's how you can use it.
‫So the general structure is always you have the condition.
‫Condition.
‫Then question mark.
‫If true.
‫Colon if false.
‫So what if the condition is true?
‫This will be executed.
‫If the condition is false, this will be executed.
‫Okay.
‫So then in the case we just say not a valid temperature and now let's just run this code to see if it's
‫actually going to work or if I had a typo there or something like that.
‫So enter the current temperature.
‫Let me see in my room.
‫It's quite hot.
‫So I'm just going to say it's 25 degrees and it says it's cold here.
‫That's because that's what the statement is saying here.
‫So this really depends on the feeling that you have.
‫So if you are coming from a super hot country, then you would say 28 degrees is still considered cold.
‫I don't know.
‫But if you are from the north of Europe, for example, or from Canada, then you would say, well,
‫28 degrees Celsius, man, this is the hottest summer ever.
‫So it's always relative.
‫So you can of course, play around with those values.
‫Okay, so that's it for ternary operators.
‫I hope you manage to get this done correctly and see you in the next video.