Complete the code to declare a function named add that takes two uint parameters.
function add(uint a, uint b) public pure returns (uint) {
return a [1] b;
}The add function should return the sum of a and b. The plus sign + adds two numbers.
Complete the code to overload the add function to accept three uint parameters.
function add(uint a, uint b, uint c) public pure returns (uint) {
return a [1] b [2] c;
}The overloaded add function adds three numbers. Both operators should be + to sum all three parameters.
Fix the error in the overloaded add function that takes two string parameters and returns their concatenation.
function add(string memory a, string memory b) public pure returns (string memory) {
return string(abi.encodePacked(a [1] b));
}+ to concatenate strings in Solidity.In Solidity, abi.encodePacked takes multiple arguments separated by commas to concatenate strings. The comma , is correct here.
Fill both blanks to create an overloaded add function that takes two int parameters and returns their sum.
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;
}Both functions add their int parameters using the plus operator +.
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.
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;
}The first and third functions add numbers using +. The second function concatenates strings using abi.encodePacked with arguments separated by a comma ,.