We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

SWITCH Function

The SWITCH function is like a more powerful IF. It checks multiple conditions and returns different values based on which condition is true. Here's an example that classifies homes into "Small," "Medium," or "Large" based on the SquareFeet column:

OrderSize =
SWITCH(
   TRUE,
   Homes[SquareFeet] <= 2000, "Small",
   Homes[SquareFeet] <= 3000, "Medium",
   "Large"
)

You might be wondering, "Why the TRUE at the beginning of the SWITCH function?" It's a bit odd, and it usually will just be TRUE, but it's specified because you can change it. It's just the value that the following conditions need to match. In this case Homes[SquareFeet] <= 2000 and Homes[SquareFeet] <= 3000 need to evaluate to TRUE to return their respective "Small" and "Medium" values.

Assignment

    • If discounted price is < $100 the sale is "Tiny"
    • If discounted price is < $200 the sale is "Mid"
    • Otherwise, it's "Massive"

Save the project and, from the course directory, submit the CLI tests.