Question: LAB 4: JavaScript Loops Part I) 1) Make an array of colors, instead of responses, call it colors. Color names go inside quotes, i.e. red.
LAB 4: JavaScript Loops Part I) 1) Make an array of colors, instead of responses, call it colors. Color names go inside quotes, i.e. "red". 2) Copy the line of the var randomNum, but instead of looking at the length of responses, look at the length of your colors array. 3) Declare a variable myColor below the randomNum variable declaration. 4) Save a randomly chosen color into the variable myColor. colors[randomNum] picks a random color from the array. Save that into the variable myColor using = 5) Write the name of the randomly chosen color to the document. See writing statement in the participation activity. Your variable myColor, with the chosen color saved inside it, must be concatenated to the string written to the document. Instead of responses[randomNum]. Use something like "The chosen color is ... " + myColor + " ..." 6) Apply the chosen color to make it the background color of the document. Use document.bgColor = myColor; Careful, please recall that JavaScript is case sensitive! Don't forget semicolons at the end of each statment. Check that it works! Every time you refresh the page, a new color paints the page and it is written on the document. Part II) Loops: Instead of writing to the console, write to the document. There is an example loop in the initial file. After each loop place the following statement. document.writeln(" "); Reference: Participation Activities 8.4.6, 8.4.7 1) Write a for loop to print the following sequence of numbers. 0 1 2 3 4 5 6 7 8 9 2) Write a for loop to print the following sequence of numbers. -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 Reference: Participation Activity 8.4.2 Note typo on 3, there should be no ; after while (c <= 20) 3) Write a while loop to print the following sequence of numbers. Same as before, write into document. Use document.write(c+" "); 5 10 15 20 25 30 35 40 45 50 4) Write a while loop to print the following sequence of numbers. 8 10 12 14 16 18
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
