Complete the code to declare a library named MathLib.
library [1] { function add(uint a, uint b) internal pure returns (uint) { return a + b; } }
MathLib.library keyword.The library name must be MathLib as declared in the code.
Complete the code to use the library function add for uint variables.
using [1] for uint; contract Calculator { function sum(uint a, uint b) public pure returns (uint) { return a.add(b); } }
SafeMath or Utils.using keyword.The using directive must refer to the library MathLib to use its add function.
Fix the error in the library function declaration to make it a pure function.
library MathLib {
function multiply(uint a, uint b) internal [1] returns (uint) {
return a * b;
}
}view instead of pure.payable or external incorrectly.The function should be marked pure because it does not read or modify state.
Fill both blanks to declare a library function that returns the minimum of two uints.
library MathLib {
function min(uint a, uint b) internal [1] returns (uint) {
return a [2] b ? a : b;
}
}view instead of pure.>.The function is pure and uses the less than operator < to find the minimum.
Fill all three blanks to create a library function that checks if a number is even.
library MathLib {
function isEven(uint num) internal [1] returns (bool) {
return num [2] 2 [3] 0;
}
}view instead of pure.!= instead of ==.The function is pure. It uses the modulo operator % to check if the remainder is equal to zero.
