Name the colour

paint-bucketsComputer programmers, web-designers, graphic designers often have to choose specific colours to design eye-catchy user interfaces. To do so they use colour codes which are used to uniquely identify each of the 16 million colours available on the RGB colour palette.

Some of the colours from this palette however have names such as red, white, blue, cyan, magenta, brown, yellow, etc.

For this challenge we are going to write a program that asks the user to type the name of colour and returns its matching colour code.

Let’s look at the code

Let’s test this code

Your task is to complete the following test plan to see if your program works as expected:

Test # Purpose Input Value Expected Output Actual Output
#1 Test to see if the program finds a colour that exists. Cyan #00FFFF
#2 Test to see if the program finds a colour that exists. Purple #8E35EF
#3 Test to see if the program displays a meaningful message if it cannot find the colour. rainbow “We cannot find your colour”
#4 Test to see if the program displays a meaningful message if the user did not enter any colour name (leave blank) “Make sure you type the name of a colour.”
#5 Test to see if the program still works without being affected by the case of the input value. pUrPLE #8E35EF

Fixing Bugs


While testing you may have noticed that test #4 did not produce the expected output.

Your task is to tweak the code to make sure it validates the user input. If the user did not type anything when asked to enter the name of the colour you will display a message saying: “Make sure you type the name of a colour.”

Final Testing


Now that you have fixed this issue, you are going to test it to see if you get the expected outcome.

Test # Purpose Input Value Expected Output Actual Output
#4 Test to see if the program displays a meaningful message if the user did not enter any colour name (leave blank) “Make sure you type the name of a colour.”

Extension Task:


Can you tweak this code so that if the user types a colour code (beginning with a “#” tag) the program finds the name of this colour.

Make sure you fully test your program!

Did you like this challenge?

Click on a star to rate it!

Average rating 3.2 / 5. Vote count: 5

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!

Tagged with: ,