I don't understand the ternary conditional?


#1



Replace this line with your code.


#2

Hello @fadlelsewefy,

a bit more Info would be helpful :rolling_eyes:

Greez, 0xB4DC0DED


#3

simply... i don't understand this code

(fuelLevel > 0) ? 'Y' : 'N';


#4

Well, if that is the case, it's kinda like a "simplyfied" if-else-statement

param comparsion-operator param ? true : false.

So, in code (example:)

var x = 5;
var y = 10;

(x < y) ? true : false;

Means the same like

var x = 5;
var y = 10;

if (x < y) {
    return true;
} else {
    return false;
}

In your case, just interpret the code like:

if (fuelLevel > 0) {
    return 'Y';
} else {
    return 'N';
}

Hope that was helpful and better to understand for you now :slight_smile:


#5

thank you very much :blush:


#6

sorry let me ask you another question

the variable means = int , char , ?


#7

In your case, it's a simple char.


#8

give me more info ????


#9

More info about?
Which types can be used?


#10

i want to know what's the kind's of variable ?


#11

Yeah, but from which variable you want to know the kind?


#12

i mean the variables include int , char ? or no ?


#13

Which variables?

If you mean the var's I've marked fat

(fuelLevel > 0) ? 'Y' : 'N';

Those can be all different kinds. Int, chars, strings.
You can even put there entire functions - but that's purposeless.
Therefor are if-else-statements made. :slight_smile:


#14

so , you mean that the variables is the ' name ' after ex : char , int ???


#15

You're confusing me, lol.


#16

ahaahahaah .. please be patient with me :smile: