0
0
Blockchain / Solidityprogramming~10 mins

Constants and immutables 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 constant value for the token name.

Blockchain / Solidity
contract Token {
    string public constant [1] = "MyToken";
}
Drag options to blanks, or click blank then click option'
ATOKEN_NAME
BtokenName
Ctoken_name
DTokenName
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or camelCase names for constants.
2fill in blank
medium

Complete the code to declare an immutable variable for the contract owner address.

Blockchain / Solidity
contract Ownership {
    address public immutable [1];

    constructor(address _owner) {
        [1] = _owner;
    }
}
Drag options to blanks, or click blank then click option'
AOWNER_ADDRESS
BownerAddress
Cowner
DOwner
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase names for immutable variables.
Trying to assign immutable variables outside the constructor.
3fill in blank
hard

Fix the error in the code by choosing the correct keyword to declare a constant.

Blockchain / Solidity
contract Example {
    uint256 public [1] VALUE = 1000;
}
Drag options to blanks, or click blank then click option'
Alet
Bimmutable
Cconstant
Dvar
Attempts:
3 left
💡 Hint
Common Mistakes
Using immutable instead of constant for fixed values.
Using JavaScript keywords like var or let.
4fill in blank
hard

Fill both blanks to declare an immutable uint variable and assign it in the constructor.

Blockchain / Solidity
contract Config {
    uint256 public [1] [2];

    constructor(uint256 _value) {
        [2] = _value;
    }
}
Drag options to blanks, or click blank then click option'
Aimmutable
Bconstant
CconfigValue
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names in declaration and assignment.
Forgetting to add the immutable keyword.
5fill in blank
hard

Fill all three blanks to declare a constant string, an immutable address, and assign the immutable in the constructor.

Blockchain / Solidity
contract Demo {
    string public constant [1] = "DemoToken";
    address public immutable [2];

    constructor(address _admin) {
        [3] = _admin;
    }
}
Drag options to blanks, or click blank then click option'
ACONSTANT_NAME
Badmin
CADMIN_ADDRESS
DTOKEN_NAME
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up constant and immutable naming conventions.
Assigning to a different variable name in the constructor.