I'm currently attempting to solve the Coinflip challenge by Ethernaut and I have trouble understanding the following line of code (after ==):

bool side = coinFlip == 1 ? true : false;

I can't seem to find any documentation on the syntax.


It's called the ternary operator: https://solidity.readthedocs.io/en/v0.4.24/miscellaneous.html?highlight=ternary

So in your example if coinFlip is equal to 1, side will be true, otherwise false.

| improve this answer | |

The bool variable side is being assigned to the result of a ternary operator check.

It's listed in the miscellaneous section of the docs, and is basically the equivalent of

if (coinFlip == 1){ 
    return true;
    return false;
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.