Practice Week 6 - COIN 70a

Parallel ARRAYS - Days

Assignment:

Create a new document called days. Create a set of parallel arrays representing:

    * names of the days of the week (start with Monday).
    * one thing you must do on each day
    * an interesting fact about that particular day (make it up - be creative)
    * Write a script that uses a For loop to write each day's name in a heading tag followed by
    a paragraph of text that describes the day. Utilize the parallel arrays you created to write
    the descriptive information for each day.

The CODE

var weekDays = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var mustDo = new Array("study", "turn in my homework", "go shopping", "take a walk", "go to the movies",
"play with the neighbor's dog", "have breakfast with friends");
var facts = new Array("Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi");

function writeArrays() {
	for (i = 0; i<weekDays.length; i++) {
		document.write("<h1>" + weekDays[i] + "</h1>");
		document.write("<p>On this day I must " + mustDo[i] + ".</p>");
		document.write("<p>The name of this day in French is " + facts[i] +".</p>");
	}

}

Instructions

So, to copy an array (correctly):
   1. Create an array.
var cups = new Array("peach smoothie", "lemonade", "mint cooler", "tropical punch");
   2. Create a second, empty array of the same length as the original array.
      TIP: Notice that I am using the length property to specify how long the new array should be.
      Think about this for a minute...when you only have 4 elements in an array, counting them is
      not a problem. But normally, you have many more elements. Rather than wasting your time counting
      them all up, get used to using the array.length property to make your life easier.
var glasses = new Array(cups.length);
   3. Copy the contents of the original array, element by element using a FOR loop, to the second array.
for (i=0; i
BACK