0
0
Blockchain / Solidityprogramming~20 mins

Function declaration and syntax in Blockchain / Solidity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Master of Function Syntax in Blockchain
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a simple Solidity function
What is the output of this Solidity function when called with input 5?
Blockchain / Solidity
pragma solidity ^0.8.0;
contract Test {
    function multiplyByTwo(uint x) public pure returns (uint) {
        return x * 2;
    }
}
A10
B5
C0
DCompilation error
Attempts:
2 left
💡 Hint
The function returns the input multiplied by 2.
Predict Output
intermediate
2:00remaining
Return value of a function with multiple returns
What does this Solidity function return when called?
Blockchain / Solidity
pragma solidity ^0.8.0;
contract Test {
    function getValues() public pure returns (uint, bool) {
        return (42, true);
    }
}
A(42, true)
B42
Ctrue
DCompilation error
Attempts:
2 left
💡 Hint
The function returns two values as a tuple.
Predict Output
advanced
2:00remaining
Output of a function with state variable update
What is the value of the state variable after calling this function once?
Blockchain / Solidity
pragma solidity ^0.8.0;
contract Counter {
    uint public count = 0;
    function increment() public {
        count += 1;
    }
}
ACompilation error
B0
C1
DUndefined
Attempts:
2 left
💡 Hint
The function increases the count by 1.
Predict Output
advanced
2:00remaining
Error type from incorrect function syntax
What error does this Solidity code produce?
Blockchain / Solidity
pragma solidity ^0.8.0;
contract Test {
    function wrongSyntax() public returns (uint) {
        return 5;
    }
}
ATypeError: Return type mismatch
BRuntime error
CNo error, compiles fine
DSyntaxError: Missing semicolon
Attempts:
2 left
💡 Hint
Check the end of the return statement.
🧠 Conceptual
expert
2:00remaining
Function visibility and access control
Which function visibility keyword allows a function to be called only from within the contract or derived contracts?
Apublic
Binternal
Cexternal
Dprivate
Attempts:
2 left
💡 Hint
Think about which keyword restricts access to the contract and its children.