CS 315 Homework 4: Javascript

Assigned: 8 October 2018   Due: 26 October 2018

This homework problem is to be done individually, not in pairs or other groups. Your completed assignment should be submitted using the Assignment Submission Page.

Your assignment involves writing unobtrusive Javascript code. Your solution should use valid HTML5 syntax. You should validate your pages using the W3 HTML validator and the CSS validator as described in class. Your Javascript code is NOT allowed to use the Prototype Framework for this assignment. Please just use unobtrusive "vanilla" Javascript as discussed in class.

Write a set of unobtrusive Javascript functions that asks the user for two date strings. Your code should pick out the month, the day and the year for each date (presumably using some form of regular expressions). You should write a standardized version of each date out to the webpage, then output the number of days that separate the two dates. Do not make any assumptions about the order of the dates, but always output a non-negative integer. If one or more input is not interpretable as a date (in one of the formats you are required to handle), your program should say that. If one or more input is not a valid date between January 1, 1950 and December 31, 2049, your program should say that. This means your program should accept February 29, 2016 (since 2016 is a leap year), but not February 29, 2003 (since 2003 is not a leap year). Your program should work for at least the following formats:

Input FormatStandardized VersionComment
9/21/05September 21, 2005 When year is two digits, assume it starts with 20 when digits are between 00 and 49, and assume it starts with 19 when digits are between 50 and 99.
09/21/05September 21, 2005
9/21/2005September 21, 2005 Assume fully specified years should be in the range 1950 to 2049.
09/03/2005September 3, 2005
9/3/2005September 3, 2005 leading zeros for month and day are allowed but optional

Notes: