Menu
Coddy logo textTech

Recap: Using Enums

Part of the Introduction To TypeScript section of Coddy's JavaScript journey — lesson 56 of 73.

challenge icon

Challenge

Easy

Create a string enum named OrderStatus with four members:

  • Pending initialized to "Pending"
  • Shipped initialized to "Shipped"
  • Delivered initialized to "Delivered"
  • Cancelled initialized to "Cancelled"

Create an interface named Order with the following properties:

  • id of type number
  • customerName of type string
  • status of type OrderStatus

Create three order objects using the Order interface:

  • order1 with id 1001, customerName "Alice Johnson", and status OrderStatus.Pending
  • order2 with id 1002, customerName "Bob Smith", and status OrderStatus.Shipped
  • order3 with id 1003, customerName "Carol Davis", and status OrderStatus.Delivered

Create a function named displayOrderInfo that takes one parameter:

  • order of type Order

The function should print a message in the format: "Order #[id] for [customerName] is [status]" and have a return type of void.

Print the following outputs:

  • Call displayOrderInfo with order1
  • Call displayOrderInfo with order2
  • Call displayOrderInfo with order3
  • Print the value of OrderStatus.Cancelled
  • Print the value of order2.status

Try it yourself

// TODO: Write your code here
// Create the OrderStatus enum, Order interface, order objects, and displayOrderInfo function

// Print the required outputs

All lessons in Introduction To TypeScript