solidity If-Else – Solving If-Else Control Structure Problem in Solidity

contract-designcontract-developmentremixsolidity

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; 
        }
     }

Best Answer

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.

Related Topic