Challenge: Color Wheel
Explore how to use Scala control structures like if and match expressions to solve a color matching challenge. Learn to output complementary secondary colors based on primary color input, and handle invalid cases effectively in your code.
We'll cover the following...
Problem Statement
You have to match all the primary colors to their complementary secondary colors. The matching is as follows:
| Primary | Secondary |
|---|---|
| blue | orange |
| yellow | purple |
| red | green |
Input
The input will be the variable testVariable which stores the primary color in the form of a String.
testVariablehas already been declared for you.
Output
For the output, print the complementary secondary color of the primary color stored in testVariable. If the input is anything but a primary color, the output should be "not a primary color".
Sample Input
"red"
Sample Output
"green"
Test Yourself
Write your code in the given area. Try the exercise by yourself first, but if you get stuck, the solution has been provided. Good luck!
Let’s go over the solution review in the next lesson.