First page Back Continue Last page Image

Screen Shot

<!DOCTYPE html>

<html>

<head>

<title>What time is it? JavaScript knows...</title>

<script src="script03.js"></script>

</head>

<body>

<h1 id="dtField"> </h1>

</body>

</html>

window.addEventListener("load",initDate,false);

function initDate() {

var now = new Date();

document.getElementById("dtField").innerHTML = timeString(now.getHours());

function timeString(theHour) {

if (theHour < 5) {

return "What are you doing up so late?";

}

if (theHour < 9) {

return "Good Morning!";

}

if (theHour < 17) {

return "No surfing during working hours!";

}

return "Good Evening!";

}

}