0
0
Blockchain / Solidityprogramming~10 mins

Enums 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 an enum named Color with values Red, Green, and Blue.

Blockchain / Solidity
[1] Color {
    Red,
    Green,
    Blue
}
Drag options to blanks, or click blank then click option'
Aclass
Bcontract
Cstruct
Denum
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'class' instead of 'enum' to declare an enum.
Using 'struct' which is for data structures, not enums.
2fill in blank
medium

Complete the code to assign the enum value Green to the variable favoriteColor.

Blockchain / Solidity
Color favoriteColor = Color.[1];
Drag options to blanks, or click blank then click option'
ABlue
BGreen
CRed
DYellow
Attempts:
3 left
💡 Hint
Common Mistakes
Using a color not declared in the enum like 'Yellow'.
Forgetting to prefix with the enum type name.
3fill in blank
hard

Fix the error in the code to correctly compare if the variable currentStatus equals Status.Active.

Blockchain / Solidity
if (currentStatus [1] Status.Active) {
    // do something
}
Drag options to blanks, or click blank then click option'
A==
B=
C!=
D=>
Attempts:
3 left
💡 Hint
Common Mistakes
Using single equals = which assigns instead of compares.
Using arrow => which is not a comparison operator.
4fill in blank
hard

Fill both blanks to create a function that returns true if the input status is Pending.

Blockchain / Solidity
function isPending(Status status) public pure returns (bool) {
    return status [1] Status.[2];
}
Drag options to blanks, or click blank then click option'
A==
B!=
CPending
DActive
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' which would check for inequality.
Using the wrong enum value like 'Active' instead of 'Pending'.
5fill in blank
hard

Fill all three blanks to create a mapping from address to Status and a function to set the status.

Blockchain / Solidity
mapping(address => Status) public [1];

function setStatus(address user, Status newStatus) public {
    [2][user] = [3];
}
Drag options to blanks, or click blank then click option'
AuserStatus
BnewStatus
Cstatus
Duser
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for the mapping in declaration and assignment.
Assigning the wrong variable instead of newStatus.