StephanieKay90
03-24-2012, 10:08 PM
Hey guys, this is an assignment for school. I have most of the code done but I cant figure out how to completely finish one part of the assignment. I bolded the part in which i'm having trouble with.
Heres the Directions per the Instructor:
Create a new HTML document that creates a listing of the days and date for the current month.
1. Create a new array, named monthArray that holds the names of the all of the months in a year, i.e. January, February…
2. Create a new array, named weekDaysArray that holds all of the days of the week, i.e. Sun, Mon, Tue,….
3. Get today’s date by using the Date object, without initializing a value for the object and save it in a variable named todaysDate.
a. Using the Date object methods, break up the value of todaysDate into variables that hold each of the pieces of the date, by assigning the values to the following variables: (see page 169 in text)
i. currYr = year
ii. currMon = month as an integer
iii. currDate = day of the month
iv. currDay = the day of the week as an integer
4. Use a document.write statement display the name of the month followed by the 4 digit year. (i.e. October 2011)
a. Use currMon as the index to get the name of the month from the monthArray created in step 1.
b. Use the variable currYr created in step 3.
c. Include a blank line after this displayed line
5. Determine the name of the first day of the current month.
a. Using the correct Date Object method, get the integer for the day of the week for the first day of the current month. (hint: you will need to pass the year, month and the day value of 1 to the Date Object to get this number)
6. Use a document.write statement to display every day of the current month on a new line in the format of the name of the day followed by the integer for the date.
a. Use a while loop to keep track of the number of days written for the month.
b. Use a for loop to write out the days of the week from the array created in step 2 under the name of the current month and year.
Example output:
October 2011
Sat 1
Sun 2
Mon 3, etc….until all 31 days are displayed.
My Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Assignment 9</title>
<script type="text/javascript">
var monthArray = new Array ("January","February","March","April","May","June","July","August","September","October","November","December");
var weekDaysArray = new Array ("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var todaysDate = new Date();
var currYr = todaysDate.getFullYear();
var currMon = todaysDate.getMonth();
var currDate = todaysDate.getDate();
var currDay = todaysDate.getDay();
document.write(monthArray[currMon] + " " +currYr);
document.write("<br />");
document.write(weekDaysArray[currDay] + "<br />");
var count = 0;
while (count < 31)
{
count++;
}
for(var count = 0 ; count < 31 ; count++)
{
document.write(weekDaysArray[count]+ "<br />");
}
</script>
</head>
<body>
</body>
</html>
Heres the Directions per the Instructor:
Create a new HTML document that creates a listing of the days and date for the current month.
1. Create a new array, named monthArray that holds the names of the all of the months in a year, i.e. January, February…
2. Create a new array, named weekDaysArray that holds all of the days of the week, i.e. Sun, Mon, Tue,….
3. Get today’s date by using the Date object, without initializing a value for the object and save it in a variable named todaysDate.
a. Using the Date object methods, break up the value of todaysDate into variables that hold each of the pieces of the date, by assigning the values to the following variables: (see page 169 in text)
i. currYr = year
ii. currMon = month as an integer
iii. currDate = day of the month
iv. currDay = the day of the week as an integer
4. Use a document.write statement display the name of the month followed by the 4 digit year. (i.e. October 2011)
a. Use currMon as the index to get the name of the month from the monthArray created in step 1.
b. Use the variable currYr created in step 3.
c. Include a blank line after this displayed line
5. Determine the name of the first day of the current month.
a. Using the correct Date Object method, get the integer for the day of the week for the first day of the current month. (hint: you will need to pass the year, month and the day value of 1 to the Date Object to get this number)
6. Use a document.write statement to display every day of the current month on a new line in the format of the name of the day followed by the integer for the date.
a. Use a while loop to keep track of the number of days written for the month.
b. Use a for loop to write out the days of the week from the array created in step 2 under the name of the current month and year.
Example output:
October 2011
Sat 1
Sun 2
Mon 3, etc….until all 31 days are displayed.
My Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Assignment 9</title>
<script type="text/javascript">
var monthArray = new Array ("January","February","March","April","May","June","July","August","September","October","November","December");
var weekDaysArray = new Array ("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var todaysDate = new Date();
var currYr = todaysDate.getFullYear();
var currMon = todaysDate.getMonth();
var currDate = todaysDate.getDate();
var currDay = todaysDate.getDay();
document.write(monthArray[currMon] + " " +currYr);
document.write("<br />");
document.write(weekDaysArray[currDay] + "<br />");
var count = 0;
while (count < 31)
{
count++;
}
for(var count = 0 ; count < 31 ; count++)
{
document.write(weekDaysArray[count]+ "<br />");
}
</script>
</head>
<body>
</body>
</html>