0
0
Blockchain / Solidityprogramming~10 mins

Function overloading in Blockchain / Solidity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a function named add that takes two uint parameters.

Blockchain / Solidity
function add(uint a, uint b) public pure returns (uint) {
    return a [1] b;
}
Drag options to blanks, or click blank then click option'
A-
B+
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
Forgetting to return the result.
2fill in blank
medium

Complete the code to overload the add function to accept three uint parameters.

Blockchain / Solidity
function add(uint a, uint b, uint c) public pure returns (uint) {
    return a [1] b [2] c;
}
Drag options to blanks, or click blank then click option'
A+
B-
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using different operators for each addition.
Using subtraction or multiplication instead of addition.
3fill in blank
hard

Fix the error in the overloaded add function that takes two string parameters and returns their concatenation.

Blockchain / Solidity
function add(string memory a, string memory b) public pure returns (string memory) {
    return string(abi.encodePacked(a [1] b));
}
Drag options to blanks, or click blank then click option'
A.
B+
C,
D&
Attempts:
3 left
💡 Hint
Common Mistakes
Using plus sign + to concatenate strings in Solidity.
Using dot or ampersand which are invalid here.
4fill in blank
hard

Fill both blanks to create an overloaded add function that takes two int parameters and returns their sum.

Blockchain / Solidity
function add(int a, int b) public pure returns (int) {
    return a [1] b;
}

function add(int a, int b, int c) public pure returns (int) {
    return a [2] b + c;
}
Drag options to blanks, or click blank then click option'
A+
B-
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using different operators in each function.
Using subtraction or multiplication instead of addition.
5fill in blank
hard

Fill both blanks to create an overloaded add function that takes two uint parameters and returns their sum, and another that takes two string parameters and returns their concatenation.

Blockchain / Solidity
function add(uint a, uint b) public pure returns (uint) {
    return a [1] b;
}

function add(string memory a, string memory b) public pure returns (string memory) {
    return string(abi.encodePacked(a,b));
}

function add(uint a, uint b, uint c) public pure returns (uint) {
    return a [2] b + c;
}
Drag options to blanks, or click blank then click option'
A+
B,
C-
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using plus sign to concatenate strings instead of comma.
Using subtraction or multiplication instead of addition for numbers.