Task
In this challenge, you were given a primary color and you had to match it to its complementary secondary color.
Solution
Let’s go over the solution step-by-step.
-
The first thing you had to figure out is that this problem requires a
switch
statement. -
Next, you had to figure out the number of cases the
switch
statement would have to cover for 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");
break;
case "yellow":
print("purple");
break;
case "red":
print("green");
break;
default:
print("not a primary color");
You can find the complete solution below:
You were required to write the code given from line 4 to line 16.
Create a free account to access the full course.
Continue your learning journey with a 14-day free trial.
By signing up, you agree to Educative's Terms of Service and Privacy Policy