0
0
Blockchain / Solidityprogramming~20 mins

Why functions define contract behavior in Blockchain / Solidity - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Smart Contract Function Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Solidity function call?

Consider this Solidity contract snippet. What will be the output when getBalance() is called after deploying the contract?

Blockchain / Solidity
contract Wallet {
    uint private balance = 100;

    function getBalance() public view returns (uint) {
        return balance;
    }
}
A0
B100
CCompilation error
DFunction does not return a value
Attempts:
2 left
💡 Hint

Look at the initial value of balance and the return statement.

🧠 Conceptual
intermediate
2:00remaining
Why do functions define contract behavior in blockchain?

Which of the following best explains why functions define contract behavior in blockchain smart contracts?

AFunctions specify the actions and rules the contract can perform and enforce.
BFunctions store the contract's data permanently on the blockchain.
CFunctions are only used to initialize contract variables once.
DFunctions automatically generate user interfaces for the contract.
Attempts:
2 left
💡 Hint

Think about what functions do in programming and how contracts interact with users.

🔧 Debug
advanced
2:00remaining
Identify the error in this Solidity function affecting contract behavior

What error will occur when calling withdraw(uint amount) in this contract?

Blockchain / Solidity
contract Bank {
    uint public balance = 50;

    function withdraw(uint amount) public returns (uint) {
        if(amount <= balance) {
            balance -= amount;
        }
        return balance;
    }
}
ANo error, function works correctly
BRuntime error: insufficient balance
CCompilation error: missing visibility specifier
DCompilation error: function declared void but returns a value
Attempts:
2 left
💡 Hint

Check the function return type and the return statement.

📝 Syntax
advanced
2:00remaining
Which option correctly defines a payable function in Solidity?

Choose the correct syntax for a function that can receive Ether payments.

Afunction deposit() public pay { /* code */ }
Bfunction deposit() payable { /* code */ }
Cfunction deposit() public payable { /* code */ }
Dfunction deposit() public payable returns (uint) { /* code */ }
Attempts:
2 left
💡 Hint

Remember the keyword to allow a function to receive Ether and the required visibility.

🚀 Application
expert
2:00remaining
What is the value of 'count' after calling 'increment()' three times?

Given this contract, what is the value of count after calling increment() three times?

Blockchain / Solidity
contract Counter {
    uint public count = 0;

    function increment() public {
        count += 1;
    }
}
ACompilation error
B0
C1
D3
Attempts:
2 left
💡 Hint

Each call to increment() adds 1 to count.