HTML and CSS Reference
In-Depth Information
Figure 12-40
lunar functions
Function Description
calcMPhase( cDay ) Returns the phase number (from 0 to 15) of the Moon for the date stored in
calcMAge( cDay ) Returns the age of the Moon for the date stored in cDay
calcMDist( cDay ) Returns the distance in Earth radii between the Earth and the Moon on the
date stored in cDay
calcMDec( cDay ) Returns the declination (latitude on the nighttime sky) of the Moon on the
date stored in cDay
calcMRA( cDay ) Returns the right ascension (longitude on the nighttime sky) of the Moon on
the date stored in cDay
calcMZodiac( cDay ) Returns the name of the constellation or sign of the zodiac in which the Moon
resides on the date stored in cDay
Each function has a Date object parameter named cDay that you can use to return
information on the Moon's status for that day. Dr. Weiss also has supplied a collection
of 16 images named phase0.jpg through phase15.jpg . Each file contains an image of the
Moon from a particular phase in its cycle. The file phase0.jpg contains an image of the
new Moon, phase8.jpg contains an image of a full moon, and so on. Dr. Weiss points
out that you can use the calcMPhase() function he's supplied to determine which of the
16 images to display for any given day.
The layout and appearance of the lunar calendar are up to you. You also can supple-
ment the contents of this Web page with any other material you think is appropriate for
the subject.
Complete the following:
1. Using your text editor, open the caltxt.css , lunartxt.htm , and lunartxt.js files from
the tutorial.12\case4 folder. Enter your name and the date in each file. Save the files
as calendar.css , lunar.htm , and lunarcal.js , respectively. The calendar.css file will be
used to store the style sheet for the lunar calendar you'll create. The lunar.htm ile
contains the Web page that Dr. Weiss wants to display on the SkyWeb Web site. The
lunarcal.js file will contain the functions required to create the lunar calendar.
2. Go to the lunar.htm file in your text editor. In the head section, add links to the calendar.
css style sheet, the moonfunc.js JavaScript file, and the lunarcal.js JavaScript file.
3. Insert an embedded script element in the head section, and use it to create a global
variable named cDay containing a date object for the date December 14, 2015.
4. Save your changes to the file, and then go to the lunarcal.js file in your text editor.
Create a function named writeDate() . The purpose of this function is to display a
date in the format Month Day, Year , where Month is the name of the month, Day is
the day of the month, and Year is the four-digit year value. The function has a single
parameter, cDay , which contains the Date object to be formatted.
5. Create a function named lunar_calendar() that displays a lunar calendar. The function
should have a single parameter also named cDay that contains the Date object you
want to use as the basis for the calendar. You can use the calendar() function created
in the tutorial as a model for your function and any supporting functions required to
complete the calendar. The calendar does not have to highlight the current date, but it
should display the correct image of the moon alongside the calendar dates.
6. Use comments to document your JavaScript code.
Search WWH ::

Custom Search