0
0
Blockchain / Solidityprogramming~10 mins

Arrays (fixed and dynamic) 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 fixed-size array of 5 integers.

Blockchain / Solidity
int[[1]] numbers;
Drag options to blanks, or click blank then click option'
A0
B10
C5
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using zero or negative numbers for array size.
Forgetting to specify the size.
2fill in blank
medium

Complete the code to declare a dynamic array of addresses.

Blockchain / Solidity
address[] public [1];
Drag options to blanks, or click blank then click option'
Ausers
Bbalances
Cowners
Daccounts
Attempts:
3 left
💡 Hint
Common Mistakes
Using fixed-size brackets instead of empty brackets.
Using singular names for arrays.
3fill in blank
hard

Fix the error in the code to add an element to a dynamic array.

Blockchain / Solidity
users.[1](msg.sender);
Drag options to blanks, or click blank then click option'
Apush
Bappend
Cadd
Dinsert
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'add' or 'append' which are not valid methods in Solidity.
Trying to assign directly without using a method.
4fill in blank
hard

Fill both blanks to declare a fixed-size array and assign a value to its first element.

Blockchain / Solidity
uint256[[1]] scores;
scores[[2]] = 100;
Drag options to blanks, or click blank then click option'
A3
B0
C1
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 1 instead of 0 for the first element.
Using zero or negative number for array size.
5fill in blank
hard

Fill all three blanks to create a dynamic array, add an element, and get its length.

Blockchain / Solidity
address[] public [1];

function addUser(address user) public {
    [1].[2](user);
}

function getUserCount() public view returns (uint) {
    return [1].[3];
}
Drag options to blanks, or click blank then click option'
Ausers
Bpush
Clength
Daccounts
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for the array in different places.
Using 'append' or 'add' instead of 'push'.
Trying to call length as a function instead of a property.