I am trying to display the current date and a name of a famous person who was born on the same date. I cannot get the name of the famous person to show up. Any ideas why? I would appreciate any help!
Here is the HTML file:
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC " //W3C//DTD XHTML1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!--
Tutorial 10
Case Problem 4
Author: Collin Klopstein
Date: December 5, 2013
This Web Page is created to display the current day's date and give a name of a famous person who is born on the same day.
-->
<title>Happy Birthday</title>
<link type="text/css" rel="stylesheet" href="date.css" />
<script type="text/javascript" src="functions.js"></script>
</head>
<body>
<div id="links">
<ul>
<li><a href="index.htm">Home</a></li>
<li><a href="birthday.htm">Happy Birthday</a></li>
<li><a href="dinnerplate.htm">Dinner Plate</a></li>
<li><a href="tempest.htm">Shakespeare</a></li>
<ul>
</div>
<div id="pic">
<img src="logo.jpg" alt="happy birthday" />
</div>
<div id="star">
<script type="text/javascript">
document.write("<p>Today's Date is</p>");
document.write(showDate());
document.write("<p>A star born today</p>");
document.write(showBirthDay(dayNumber()));
</script>
</div>
</body>
</html>
Here is the JavaScript File:
/*
New Perspectives on HTML and XHTML 5th Edition
Tutorial 10
Case Problem 4
Function List:
showDate
Used to display the date in the form "Weekday, Month Day, Year"
dayNumber
Used to calculate the day number (1 - 366) of a given date
showBirthDay
Used to display a famous birthday falling on a given date
*/
var births = new Array();
births[1] = "J.D. Salinger (1919) - Author";
births[2] = "Isaac Asimov (1920) - Author";
... // lots of birthdays here
births[364] = "Jude Law (1972) - Actor";
births[365] = "Rudyard Kipling (1865) - Author";
births[366] = "Bonnie Prince Charlie (1720) - Attempted to seize England";
function showDate() {
thisDate = new Date();
var thisWDay=thisDate.getDay();
var thisDay=thisDate.getDate();
var thisMonth=thisDate.getMonth();
var thisYear=thisDate.getFullYear();
var mName = new Array("January", "February", "March", "April", "May",
"June", "July", "August", "September", "October","November", "December");
var wdName = new Array("Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday");
return wdName[thisWDay]+", "+mName[thisMonth]+" "+thisDay+", "+thisYear;
}
function dayNumber() {
thisDate = new Date();
var leapYearDate = thisDate.setFullYear(2004);
var baseDate = new Date("January 1, 2004");
days = Math.floor((leapYearDate - baseDate)/(1000*60*60*24)+1);
return days;
}
function showBirthDay(day) {
return births[day];
}