Using the functions you wrote in previous assignments and the leap year function provided, write a function to determine the day of the week a person was born given his or her birthday. The following steps should be used to find the day of the week corresponding to any date from 1901 through the present.
In the following explanation, the following terms will be helpful. Assuming I type in my birthday as "6 10 1981":
The month is 6.
The day of the month is 10.
The year is 1981.
yy
. Simply subtract 1900
from the year to get this. Also store a copy of this
number in a variable called total
.
total
. For example, if the
person was born in 1983, divide 83 by 4 and add 20 to
total
.
total
.
monthOffset()
you wrote,
find the "month offset" and add it to total
.
total
. You can use the function isLeap()
provided to determine if the year is a leap year.
total
is divided by 7.
Pass this remainder to the function weekdayName()
you wrote to determine the day of the week the person was born.
monthName()
you wrote
to show the month name rather than its number.
Whew. Here's some code to get you started.
Welcome to Mr. Mitchell's fantastic birth-o-meter! All you have to do is enter your birthday, and it will tell you the day of the week on which you were born. Some automatic tests.... 12 10 2003 => Wednesday, December 10, 2003 2 13 1976 => Friday, February 13, 1976 2 13 1977 => Sunday, February 13, 1977 7 2 1974 => Tuesday, July 2, 1974 1 15 2003 => Wednesday, January 15, 2003 10 13 2000 => Friday, October 13, 2000 Now it's your turn! What's your birthday? Birthday (mm dd yyyy): 11 11 2010 You were born on Thursday, November 11, 2010!
©2003–2016 Graham Mitchell
This assignment is licensed under a
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States License.