2

Why does below control structure return 250 in both value scenarios?

function bonusCalculate(uint _value) public pure returns(uint) {

        if(_value <= 50 ether) {
          return 250;
        } else if (_value >= 100 ether) {
          return 500; 
        }
     }
5

because your code is equivalent to

function bonusCalculate(uint _value) public pure returns(uint) {

        if(_value <= 50*1000000000000000000) {
          return 250;
        } else if (_value >= 100*1000000000000000000) {
          return 500; 
        }
     }

1 ether= 1000000000000000000.

  • 1
    Legendary Badr, forgot about that – NowsyMe Mar 31 '18 at 23:45

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.