Solution Review: Color Wheel

In the following lesson, we will go over the solution of the challenge: Color Wheel.

We'll cover the following


In this challenge, you were provided a primary color and you had to match it to its complementary secondary color.


Let’s go over the solution step-by-step.

  • The first thing you had to figure out is that this problem requires a match expression.

  • Next, you had to figure out the number of cases the match expression would require to cover all the possible scenarios. We had one case for each primary color along with a default case if the input was anything but a primary color.

case "blue" => print("orange")
case "yellow" => print("purple")
case "red" => print("green")
case _ => print("not a primary color")

You can find the complete solution below:

You were required to write the code from line 3 to line 8.

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy