0
Can someone please explain this code?
The course that i'm taking didn't explain it at all https://code.sololearn.com/WpcrgMGFcCsh/?ref=app
4 Answers
+ 3
Its ternary operater. Read it like a sentence. But anyways, think about it like this: Everything up until the question mark is the question. The indentation is weird, but it should read:
isRaining ? ....
It takes that statement or whatever and gets a boolean True False value from it.
Then you got two choices here.
If the statement is true, it does the first code before the colon. If false, it does the code after. The colon ':' is to seperate the choices.
So then it reads: Is it raining? If yes, you need a jacket. If no, you have no need for a jacket.
But it would only print one of those.
+ 1
It's raining.
Is it raining? You need a coat.
It's not raining.
Is it raining? No need for a coat.
0
Slick yep i mean this ? : thing i don't understand what it dose and the variable name after the variable
0
Slick thanks