The Color Machine


You are creating a beautiful machine that has the power to create any color in the world using RGB (RED-GREEN-BLUE). Give the machine 6 buttons, each one changing a different aspect of the color spectrum. This is your chance to try CSS styling.

Read this Intro to CSS to learn about how to use CSS to style your buttons.

Here is an example of a completed machine.


Directions
  1. Create a standard HTML page with a label and a pair of buttons. For the label (use <p> or <div>). One is PLUS button, the other a MINUS. The buttons should each have id and onClick attributes,

  2. In the <script> section, create three variable, called redColor, blueColor, and greenColor and set each to 127. Display their values in the label by changing myLabel.innerHTML.

  3. Inside the <head> section of your HTML page, add a section like this:

    <style type="text/css"> </style>

  4. Inside this section, add CSS styling for your PLUS and MINUS buttons to be red. So if one button has an id="redPlus", you would create a CSS selector:

    .redPlus { background-color: red; }

  5. Next, when each button is clicked, it should run a function and change redColor accordingly, up or down. You should see the change in the label.

  6. Now, set the color of the page to reflect the RGB colors. The code is something like (pay attention to the quotes). :

    PAGE BG COLOR = 'rgb(' + redColor + ',' + greenColor + ',' + blueColor + ')';

    Of course PAGE BG COLOR is pseudo-code.

  7. Repeat what you created for the Red buttons to add a pair of Green and a pair of Blue buttons.

  8. Do you see the same code in multiple places? Consolidate it! Think about creating a single function that changes the color of the page and also the contents of the label. After a button changes its color variable, have every button call the changePage () function. This way you only have to maintain one set of code to update the page.

  9. If you are enjoying playing with colors, create a Contrast Box on the page, and swap one of the RGB values in it to contrast with the color of the page. So if the page is RGB, make the contrast box BGR. Do the colors look different in contrast to each other?

  10. Style your page, make it look good, add any variations you'd like.







(c) 2018 by Code Craft Academy