0
0
Blockchain / Solidityprogramming~10 mins

Mappings in Blockchain / Solidity - Interactive Code Practice

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

Complete the code to declare a mapping from address to uint.

Blockchain / Solidity
mapping(address => uint) public [1];
Drag options to blanks, or click blank then click option'
Aaccounts
Bbalance
Cbalances
Dusers
Attempts:
3 left
💡 Hint
Common Mistakes
Using singular names like 'balance' which is less common.
Using unrelated names like 'users' which is vague.
2fill in blank
medium

Complete the code to assign 100 to the sender's balance in the mapping.

Blockchain / Solidity
[1][msg.sender] = 100;
Drag options to blanks, or click blank then click option'
Abalances
Baddress
Cmapping
Dmsg
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'address' or 'msg' which are not mapping variables.
Trying to assign directly to 'mapping' keyword.
3fill in blank
hard

Fix the error in the code to correctly check if an address has a balance greater than zero.

Blockchain / Solidity
if ([1][user] > 0) {
    // do something
}
Drag options to blanks, or click blank then click option'
Abalance
Baddress
Cmapping
Dbalances
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'balance' which is undefined.
Using 'mapping' or 'address' which are keywords or types, not variables.
4fill in blank
hard

Fill both blanks to create a mapping from address to bool and set the sender's value to true.

Blockchain / Solidity
mapping([1] => [2]) public approved;
approved[msg.sender] = true;
Drag options to blanks, or click blank then click option'
Aaddress
Bbool
Cuint
Dstring
Attempts:
3 left
💡 Hint
Common Mistakes
Using uint or string as value type instead of bool.
Swapping key and value types.
5fill in blank
hard

Fill all three blanks to create a mapping from uint to string, assign a value, and retrieve it.

Blockchain / Solidity
mapping([1] => [2]) public names;
names[[3]] = "Alice";
string memory name = names[1];
Drag options to blanks, or click blank then click option'
Auint
Bstring
C1
Daddress
Attempts:
3 left
💡 Hint
Common Mistakes
Using address as key type here instead of uint.
Using wrong key value like address or 0.