(this is a funny joke question) :-{

I don't understand why this doesn't return 11. I hope someone can help me with this.

Thanks in advance.

pragma solidity 0.8.0;

contract a {
    uint256 numberA = 5;
    string operator = "+";
    uint256 numberB = 6;

    function add() external view returns(string memory)
        return(numberA + operator + numberB);

1 Answer 1


You don't have to specify the operator as a string.

Just remove the operator + part.

Also, adding two uint256's returns a uint256. You will also need to change the return type of the add() function to uint256 instead of string memory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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