LESSON 08 – THE DATE CLASS

 

WORK

 

QUESTION 1

Write the script needed to display a message depending on the time.

 

Time                           Message

 

5AM – 12PM              “Good morning”

 

12PM – 6PM             “Good afternoon”

 

6PM – 10PM              “Good evening”

 

10PM – 5AM             “Good night”

 

You can test your script by changing the time on your computer to a different time range and then opening the page.

 

Hint: You need to work with the 24 hour clock.  The number for 5PM is actually 17.

 

Hint 2: You will have to use the && to check that the hour is greater than a number and less than another.

 

Hint 3: You will probably have to use the || for the condition of the “Good night” if statement.

 

QUESTION 2

Get the user to enter their birth date.  Then tell the user the day of the week on which they were born.

 

QUESTION 3

Create a form with a button.   When the button is clicked, the window pops up showing the message “The webpage was open for x seconds before you clicked the button.”

 

Hint 1: You need to create a Date object when the page is loaded.  To do this, place the following code inside the body section.

 

<script type="text/javascript">

var d1 = new Date();

</script>

 

Hint 2: When the button is clicked, it will execute a function.  Inside that function, you need to create a 2nd date object.

 

Hint 3:Inside the function, once you have your two Date objects, you can do the calculations using.

 

ellapsedSeconds = difference of hour * 3600 + difference of minutes * 60 + difference of seconds