PDA

View Full Version : Can Someone Decipher This Line of Code Please?



Bobafart
Sep 9th, 2007, 04:16 AM
What does this line of code mean? I think it is some kind of if/then statement. Can someone decipher it please?

time, hours, minutes and seconds are all variables



time = (minutes<=9 ? " Time left: "+ hours + "h : " + minutes : minutes) + "m : " + seconds + "s";


thanks

rnd me
Sep 9th, 2007, 07:39 AM
if < 9 minutes, then time = " Time left: "+ hours + "h : " + minutes ;+ "m : " + seconds + "s";

if > 9 minutes, then time = minutes+ "m : " + seconds + "s";

Kor
Sep 9th, 2007, 08:00 AM
It is a ternary operator. The simple ternary looks like

condition ? statement_if_true : statement_if_false

it is the short notation for an if-else:

if(condition){
statement_if_true
}
else{
statement_if_false
}