Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy won't my javascript code display a name of a famous person born on the current date?
    primarykey
    data
    text
    <p>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!</p> <p>Here is the HTML file:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;!DOCTYPE html PUBLIC " //W3C//DTD XHTML1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;!-- 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. --&gt; &lt;title&gt;Happy Birthday&lt;/title&gt; &lt;link type="text/css" rel="stylesheet" href="date.css" /&gt; &lt;script type="text/javascript" src="functions.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="links"&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="index.htm"&gt;Home&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="birthday.htm"&gt;Happy Birthday&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="dinnerplate.htm"&gt;Dinner Plate&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="tempest.htm"&gt;Shakespeare&lt;/a&gt;&lt;/li&gt; &lt;ul&gt; &lt;/div&gt; &lt;div id="pic"&gt; &lt;img src="logo.jpg" alt="happy birthday" /&gt; &lt;/div&gt; &lt;div id="star"&gt; &lt;script type="text/javascript"&gt; document.write("&lt;p&gt;Today's Date is&lt;/p&gt;"); document.write(showDate()); document.write("&lt;p&gt;A star born today&lt;/p&gt;"); document.write(showBirthDay(dayNumber())); &lt;/script&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Here is the JavaScript File:</p> <pre><code>/* 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]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload