1

I am trying to implement a simple smart contract on Remix IDE (using Genache as my local blockchain)

Here is the code:

pragma solidity ^0.4.24;

contract Aa {

    uint public myuint;

    function set(uint _var) public {
            require(_var == 5 || 99, "Not 5 or 99!");
        myuint = _var;
    }

    function get() public view returns (uint){
        return myuint;
    }
}

I am getting an error: "TypeError: Operator || not compatible with types bool and int_const 99 require(_var == 5 || 99, "Not 5 or 99!");"

1

in the question the code has an error on line:

require(_var == 5 || 99, "Not 5 or 99!");

This tells the compiler to compare _var == 5 and 99 as opposed to comparing _var == 5 and _var == 99

The correct code is:

pragma solidity ^0.4.24;

contract Aa {

    uint public myuint;

    function set(uint _var) public {
            require(_var == 5 || _var == 99, "Not 5 or 99!");
        myuint = _var;
    }

    function get() public view returns (uint){
        return myuint;
    }
}

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.