0
0
Blockchain / Solidityprogramming~10 mins

State variables 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 state variable named count of type uint.

Blockchain / Solidity
contract Counter {
    [1] count;
}
Drag options to blanks, or click blank then click option'
Afunction
Buint
Cevent
Dmapping
Attempts:
3 left
💡 Hint
Common Mistakes
Using function instead of a data type.
Trying to declare state variables without a type.
2fill in blank
medium

Complete the code to initialize the state variable owner with the address of the contract creator.

Blockchain / Solidity
contract Ownership {
    address public owner = [1];
}
Drag options to blanks, or click blank then click option'
Athis
Bowner
Cmsg.sender
Daddress(0)
Attempts:
3 left
💡 Hint
Common Mistakes
Using this which refers to the contract itself, not the creator.
Using address(0) which is the zero address.
3fill in blank
hard

Fix the error in the code by completing the declaration of the state variable balance as a private unsigned integer.

Blockchain / Solidity
contract Wallet {
    [1] uint balance;
}
Drag options to blanks, or click blank then click option'
Apublic
Bexternal
Cinternal
Dprivate
Attempts:
3 left
💡 Hint
Common Mistakes
Using external which is invalid for state variables.
Using public when privacy is needed.
4fill in blank
hard

Fill both blanks to declare a state variable data as a public string and initialize it with "Hello".

Blockchain / Solidity
contract Example {
    [1] public data = [2];
}
Drag options to blanks, or click blank then click option'
Astring
B"Hello"
C"World"
Dbytes
Attempts:
3 left
💡 Hint
Common Mistakes
Using bytes instead of string for text.
Forgetting quotes around the text.
5fill in blank
hard

Fill all three blanks to declare a private unsigned integer totalSupply, initialize it to 1000, and make it accessible via a public function getSupply.

Blockchain / Solidity
contract Token {
    [1] uint totalSupply = [2];
    function getSupply() public view returns (uint) {
        return [3];
    }
}
Drag options to blanks, or click blank then click option'
Aprivate
B1000
CtotalSupply
Dpublic
Attempts:
3 left
💡 Hint
Common Mistakes
Using public instead of private for the variable.
Returning a wrong variable or literal in the function.