In: Computer Science
<!DOCTYPE html> <html> <body> <script> // // The colors red, blue, and yellow are known as the primary colors because they // cannot be made by mixing other colors. When you mix two primary colors, you // get a secondary color, as shown here: // // When you mix red and blue, you get purple. // When you mix red and yellow, you get orange. // When you mix blue and yellow, you get green. // // Design a program that prompts the user to enter the names of two primary colors // to mix. If the user enters anything other than “red,” “blue,” or “yellow,” the // program should display an error message. Otherwise, the program should display // the name of the secondary color that results. // function findSecondaryColor(color1, color2) { ///////////////////////////////////////////////////////////////////////////////// // Insert your code between here and the next comment block. Do not alter // // any code in any other part of this file. // ///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// // Insert your code between here and the previous comment block. Do not alter // // any code in any other part of this file. // ///////////////////////////////////////////////////////////////////////////////// } var color1 = prompt("What is the first primary color you'd like to mix? (red, blue or yellow) "); var color2 = prompt("What is the first second color you'd like to mix? (red, blue or yellow) "); alert(findSecondaryColor(color1, color2)); </script> </body> </html>
<!DOCTYPE html>
<html>
<body>
<script>
//
// The colors red, blue, and yellow are known as the primary colors
because they
// cannot be made by mixing other colors. When you mix two primary
colors, you
// get a secondary color, as shown here:
//
// When you mix red and blue, you get purple.
// When you mix red and yellow, you get orange.
// When you mix blue and yellow, you get green.
//
// Design a program that prompts the user to enter the names of two
primary colors
// to mix. If the user enters anything other than “red,” “blue,” or
“yellow,” the
// program should display an error message. Otherwise, the program
should display
// the name of the secondary color that results.
//
function findSecondaryColor(color1, color2) {
/////////////////////////////////////////////////////////////////////////////////
// Insert your code between here and the next comment block. Do not
alter //
// any code in any other part of this file. //
/////////////////////////////////////////////////////////////////////////////////
if((color1=="red" && color2=="blue")||
(color1=="blue" && color2=="red"))
return "purple";
else if((color1=="red" &&
color2=="yellow")||(color1=="yellow" &&
color2=="red"))
return "orange"
else if((color1=="blue" &&
color2=="yellow")||(color1=="yellow" &&
color2=="blue"))
return "green"
else
return "Invalid Input";
/////////////////////////////////////////////////////////////////////////////////
// Insert your code between here and the previous comment block. Do
not alter //
// any code in any other part of this file. //
/////////////////////////////////////////////////////////////////////////////////
}
var color1 = prompt("What is the first primary color
you'd like to mix? (red, blue or yellow) ");
var color2 = prompt("What is the first second color you'd like to
mix? (red, blue or yellow) ");
alert(findSecondaryColor(color1, color2));
</script>
</body>
</html>
/* PLEASE UPVOTE */