Reputation: 5
if (props.name == "Computer"){
if (result == "Won"){
result = "Lost";
}
else if (result == "Lost"){
result = "Won";
}
}
Tried converting to ternary, but failed to do so. (Have no idea how to mix up the first and second line). Also, not sure about "HAVE NO IDEA WHAT TO PUT" this spot.
result =="Won" ? result="Lost": result=="Lost" ? result="Won" : <HAVE NO IDEA WHAT TO PUT>;
Upvotes: 0
Views: 1240
Reputation: 9012
There are several different cases in your logic. Perhaps it's unclear to you. But this is what your attempts with the ternary operator have revealed:
props.name
could be something other than "Computer". What should be printed then?result
could be something other than just "Won"
or "Lost"
Anyway, let's build this ternary operator up:
result = props.name == "Computer" ? <YOUR CURRENT LOGIC> : <WHATEVER HAPPENS WHEN PROPS IS NOT COMPUTER>;
I am simply going to have the code return "result" as-is whenever we hit a case that was not defined by your if-else:
result = (props.name == "Computer" ? (result == "Won" ? "Lost" : "Won" ) : result);
Upvotes: 1
Reputation: 21
result = (props.name == "Computer" ? (result == "Won" ? "Lost" : "Won") : "What you want when props.name is not Computer");
Upvotes: 1