Challenge: Enumerated Types

Test your skills in implementing enumerated types in this challenge.

We'll cover the following

Problem Statement

Assume you have an app that fetches data from a remote server. Depending on the type of response received from the server, the app could have one of the following states:

  • done: The app received the response successfully.
  • waiting: The app is waiting for the response.
  • error: The app received an error from the server.

Challenge #1: Declare the enumeration Status to represent the above three cases.

Challenge #2: Print the following message for each status using the switch block.

  • Status.done: The data is ready!
  • Status.waiting: The app is waiting on a response from the server.
  • Status.error: An error occurred.

Challenge #3: Add one more status: delayed to Status. Add the code to handle the default case.

Get hands-on with 1400+ tech skills courses.