var openA;
var dayA;
var weekendA = 2;
-
no problem with this one:
openA = ( dayA == weekendA) ? 12 : 9;
-
i’d like to know the correct way to do this one:
openA = ( dayA == weekendA) ? print(“hallo”) : print(“bye”);
thanks for your help and time.
You can’t use the ternary operator as a function call without assignation. print() doesn’t returns void.
Use If/Else, or maybe try to explain more of what it is you want to accomplish with that statement (how would openA = print(“hallo”) work for example).
As well, since you are performing a function call, the ternary operator isn’t going to save you a branch anyway, so it’s not an improvement performance-wise over if/else.
print((dayA == weekendA) ? "hallo" : "bye");
Unless you also want to assign hallo to openA:
openA = (dayA == weekendA) ? "hallo" : "bye";
print(openA);
thanks alot. i found very usefull both of them:
print((dayA == weekendA) ? “hallo” : “bye”);
openA = (dayA == weekendA) ? “hallo” : “bye”;
print(openA);
i solved my problem in these 2 ways:
openA = ( dayA == weekendA ) ? ( week++ ) : ( week-- ) ;
print ( openA );
print ( week );
var openA = 2;
var dayA = 5;
var weekendA = 5;
var week = 10;
openA = ( dayA == weekendA) ? (week + dayA) + 2 : (week - dayA) - 2;
print (openA);
sorry i did not explain the problem in the first post;
i just wanted to know if it is possible to insert inputs more complex than just numbers in this
variable = condition ? value if true : value if false;
just in case, if i need to use brackets is it correct to think like this?
variable = condition ? value if true : (((week+1)/2)*3);