0
0
Blockchain / Solidityprogramming~10 mins

Return values 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 return the stored value from the function.

Blockchain / Solidity
function getValue() public view returns (uint) {
    return [1];
}
Drag options to blanks, or click blank then click option'
AgetValue
Buint
Cvalue
Dreturn
Attempts:
3 left
💡 Hint
Common Mistakes
Returning the function name instead of the variable.
Returning the type instead of the variable.
Using the keyword 'return' twice.
2fill in blank
medium

Complete the code to return the sum of two numbers.

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 instead of addition.
Using multiplication or division operators by mistake.
3fill in blank
hard

Fix the error in the return statement to correctly return the balance.

Blockchain / Solidity
function getBalance() public view returns (uint) {
    uint balance = 100;
    return [1];
}
Drag options to blanks, or click blank then click option'
Abalance
Bbal
Cbalance()
DgetBalance
Attempts:
3 left
💡 Hint
Common Mistakes
Returning a variable name that does not exist.
Adding parentheses to a variable name.
Returning the function name instead of the variable.
4fill in blank
hard

Fill both blanks to return the product of two numbers plus 1.

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

Fill both blanks to return a formatted string with the user's name and age.

Blockchain / Solidity
function getUserInfo(string memory name, uint age) public pure returns (string memory) {
    return string(abi.encodePacked([1], ": ", [2], " years old"));
}
Drag options to blanks, or click blank then click option'
Aname
Bage
Cstring(age)
DtoString(age)
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to concatenate a number without converting it to string.
Using the wrong function to convert number to string.
Missing the variable name for the first blank.