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
intermediate2: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; } }
Attempts:
2 left
💡 Hint
The function returns the input multiplied by 2.
✗ Incorrect
The function multiplyByTwo takes an unsigned integer and returns its value multiplied by 2. So input 5 returns 10.
❓ Predict Output
intermediate2: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); } }
Attempts:
2 left
💡 Hint
The function returns two values as a tuple.
✗ Incorrect
The function returns two values: an unsigned integer 42 and a boolean true as a tuple.
❓ Predict Output
advanced2: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; } }
Attempts:
2 left
💡 Hint
The function increases the count by 1.
✗ Incorrect
The increment function adds 1 to the state variable count. Initially 0, after one call it becomes 1.
❓ Predict Output
advanced2: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; } }
Attempts:
2 left
💡 Hint
Check the end of the return statement.
✗ Incorrect
The return statement is missing a semicolon at the end, causing a syntax error.
🧠 Conceptual
expert2:00remaining
Function visibility and access control
Which function visibility keyword allows a function to be called only from within the contract or derived contracts?
Attempts:
2 left
💡 Hint
Think about which keyword restricts access to the contract and its children.
✗ Incorrect
The 'internal' keyword restricts function access to the contract itself and contracts that inherit from it.