0
0
Blockchain / Solidityprogramming~10 mins

Contract structure and syntax 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 contract named MyContract.

Blockchain / Solidity
contract [1] {
}
Drag options to blanks, or click blank then click option'
AMyContract
Bmycontract
CContract
DmyContract
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or different casing for 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'
Aint
Buint
Cstring
Dbool
Attempts:
3 left
💡 Hint
Common Mistakes
Using signed integer int or wrong types like string or bool.
3fill in blank
hard

Fix the error in the function declaration to make it a public function named increment.

Blockchain / Solidity
contract Counter {
    uint public count;
    function [1]() public {
        count += 1;
    }
}
Drag options to blanks, or click blank then click option'
AIncrement
Binc
Cincrement
DincrementCount
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase first letter or different function names.
4fill in blank
hard

Complete the code to declare a constructor that sets count to zero.

Blockchain / Solidity
contract Counter {
    uint public count;
    constructor() { {
        count {BLANK_2}} 0;
    }
}
Drag options to blanks, or click blank then click option'
A{
B=
C;
D}
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong symbols like ';' instead of '{' or '='.
5fill in blank
hard

Fill both blanks to complete a function that returns the current count.

Blockchain / Solidity
contract Counter {
    uint public count;
    function getCount() public view returns({BLANK_1}}) { {
        return {{BLANK_2}};
    }
}
Drag options to blanks, or click blank then click option'
Auint256
B{
Ccount
Duint
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong return types, missing braces, or returning wrong variables.