0
0
Blockchain / Solidityprogramming~20 mins

Why Solidity is the language of Ethereum in Blockchain / Solidity - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Ethereum Solidity Master
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?

Consider this simple Solidity function that returns the sum of two numbers:

function add(uint a, uint b) public pure returns (uint) {
    return a + b;
}

What will be the output when calling add(5, 7)?

Blockchain / Solidity
function add(uint a, uint b) public pure returns (uint) {
    return a + b;
}
A57
B12
CError: function does not return a value
D0
Attempts:
2 left
💡 Hint

Think about what adding two numbers means in Solidity.

🧠 Conceptual
intermediate
2:00remaining
Why is Solidity the preferred language for Ethereum smart contracts?

Which of the following reasons best explains why Solidity is the main language used for Ethereum smart contracts?

AIt is the only programming language that can be compiled to machine code.
BIt is a low-level language like assembly, making it faster than other languages.
CIt was created by Bitcoin developers and is used across all blockchains.
DIt is designed specifically to interact with the Ethereum Virtual Machine (EVM) and supports contract-oriented programming.
Attempts:
2 left
💡 Hint

Think about what makes a language suitable for Ethereum smart contracts.

🔧 Debug
advanced
2:00remaining
What error does this Solidity code produce?

Examine this Solidity code snippet:

contract Test {
    uint public value;
    function setValue(uint _value) public {
        value = _value;
    }
    function getValue() public view returns (uint) {
        return value;
    }
    function resetValue() public {
        value = ;
    }
}

What error will the compiler show?

ASyntaxError: Expected expression after '=' in resetValue function
BTypeError: Cannot assign uint to function
CNo error, code compiles successfully
DRuntimeError: Division by zero
Attempts:
2 left
💡 Hint

Look carefully at the assignment in resetValue.

🚀 Application
advanced
2:00remaining
How does Solidity handle contract inheritance?

Given these two contracts:

contract A {
    function greet() public pure returns (string memory) {
        return "Hello from A";
    }
}

contract B is A {
    function greet() public pure returns (string memory) {
        return "Hello from B";
    }
}

If you call greet() on contract B, what will be the output?

ACompilation error due to duplicate function names
B"Hello from A"
C"Hello from B"
D"Hello from A and B"
Attempts:
2 left
💡 Hint

Think about how function overriding works in Solidity inheritance.

Predict Output
expert
2:00remaining
What is the value of the mapping after this Solidity code runs?

Consider this Solidity contract snippet:

contract Example {
    mapping(address => uint) public balances;

    function updateBalance(address user, uint amount) public {
        if (amount > 100) {
            balances[user] = amount;
        } else {
            balances[user] = 0;
        }
    }
}

After calling updateBalance(0x1234..., 50) and then updateBalance(0x1234..., 150), what is the final value of balances[0x1234...]?

A150
B50
C0
DUndefined (mapping key does not exist)
Attempts:
2 left
💡 Hint

Look at how the function updates the balance based on the amount.