-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbug prevention with enums
48 lines (38 loc) · 1.43 KB
/
bug prevention with enums
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
pragma solidity ^0.8.0;
contract enumsLearn{
enum frenchFriesSize {LARGE, MEDIUM, SMALL}
frenchFriesSize choice;
frenchFriesSize constant defaultChoice = frenchFriesSize.MEDIUM;
function setSmall() public {
choice = frenchFriesSize.SMALL;
}
function getChoice() public view returns(frenchFriesSize) {
return choice;
}
function getDefaultChoice() public pure returns (uint) {
return uint(defaultChoice);
}
}
/*
EXCERCISE:
// 1. create an enum for the color of shirts called shirtColor and set it to the options of either RED or WHITE or BLUE
// 2 create a data of shirtColor called defaultChoice which is a constant set to the color BLUE
// 3. create a data of shirtColor called choice and don't initiate the value
// 4. create a function called setWhite which changes the shirt color of shirtColor to white
// 5. create a function getChoice which returns the current choice of shirtColor
// 6. create a function getDefaultChoice which returns the default choice of shirtColor
*/
contract shirtColors {
enum shirtColor {RED, WHITE, BLUE}
shirtColor constant defaultChoice = shirtColor.BLUE;
shirtColor choice;
function setWhite() public {
choice = shirtColor.WHITE;
}
function getChoice() public view returns(shirtColor) {
return choice;
}
function getDefaultChoice() public pure returns(shirtColor) {
return defaultChoice;
}
}