5.8% Acceptance

In this lab you'll be understanding and using Enums in Solidity

Step 1: Create an Enum named House

In Solidity, an Enum is a user-defined type that consists of a set of named constants. Let's create an Enum named House with three values SMALL, MEDIUM, LARGE.

enum House { SMALL, MEDIUM, LARGE }

Step 2: Declare a Variable of Enum Type

Declare a variable of the House enum type we created in the previous step.

House public houseChoice;

This variable houseChoice will store the value of the House enum.

Step 3: Create a Function setLarge()

Create a function named setLarge(). This function will set the value of the houseChoice to LARGE.

function setLarge() public { houseChoice = House.LARGE; }

Step 4: Create a Function getChoice()

Create another function getChoice(). This function will return the current value of our houseChoice variable.

function getChoice() public view returns (House) { return houseChoice; }

After the contract is deployed, we can use the setLarge() function to set the houseChoice as LARGE and verify it using the getChoice() function.

Note: Make sure the functions are public so they can be called from outside the contract.