Week 6 Practice - COIN 70a

Colors - an ARRAY

Instructions

Create a new document called colors. Prompt the user for her top five favorite colors. Assign the results to an array and then write the colors to the page in alphabetical order beginning with A.

Human Logic Exercise

  1. GET 5 favorite colors from user.
  2. Create an array of colors
  3. Assign user's colors to array.
  4. SORT the array

Colors Array CODE

var colors = new Array();
		colors[0] = prompt("What is your first favorite color?", "");
		colors[1] = prompt("What is your second favorite color?", "");
		colors[2] = prompt("What is your third favorite color?", "");
		colors[3] = prompt("What is your fourth favorite color?", "");
	    colors[4] = prompt("What is your fifth and final favorite color?", "");

function writeColors() {
	document.write(colors);
}

colors.sort();
BACK