0
0
Blockchain / Solidityprogramming~10 mins

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

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a simple Solidity contract named MyContract.

Blockchain / Solidity
contract [1] {
    // contract code
}
Drag options to blanks, or click blank then click option'
AMyContract
BEthereum
CSolidity
DBlockchain
Attempts:
3 left
💡 Hint
Common Mistakes
Using reserved words like 'Solidity' or 'Ethereum' as contract names.
Using lowercase or invalid characters in the contract name.
2fill in blank
medium

Complete the code to declare a public state variable of type uint named count.

Blockchain / Solidity
contract Counter {
    [1] public count;
}
Drag options to blanks, or click blank then click option'
Abool
Buint
Cstring
Daddress
Attempts:
3 left
💡 Hint
Common Mistakes
Using string for numeric values.
Using bool which only holds true or false.
3fill in blank
hard

Fix the error in the function declaration to make it a public function that increments count.

Blockchain / Solidity
contract Counter {
    uint public count;
    function increment() [1] {
        count += 1;
    }
}
Drag options to blanks, or click blank then click option'
Aprivate
Bexternal
Cpublic
Dinternal
Attempts:
3 left
💡 Hint
Common Mistakes
Using private or internal which restrict access.
Omitting the visibility keyword entirely.
4fill in blank
hard

Fill both blanks to create a mapping from address to uint named balances and a function to update it.

Blockchain / Solidity
contract Wallet {
    mapping([1] => [2]) public balances;

    function updateBalance(address user, uint amount) public {
        balances[user] = amount;
    }
}
Drag options to blanks, or click blank then click option'
Aaddress
Buint
Cstring
Dbool
Attempts:
3 left
💡 Hint
Common Mistakes
Using string as key or value in mapping incorrectly.
Using bool which is not suitable for balances.
5fill in blank
hard

Fill all three blanks to create a function that returns the balance of a given address.

Blockchain / Solidity
contract Wallet {
    mapping(address => uint) public balances;

    function getBalance([1] user) public view returns ([2]) {
        return balances[[3]];
    }
}
Drag options to blanks, or click blank then click option'
Aaddress
Buint
Cuser
Dbool
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong parameter types like bool.
Returning the wrong type or using incorrect variable names.