Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <meta name="group" content="116">
- <meta name="author" content="Michaela Stenljung" "Jakob Hoverbrant">
- <title>Weekday Calculator</title>
- <style>
- body {
- background-color: #f5f5f5; border-style: outset;
- }
- h1 {
- font-size: 275%; color: #171769; padding: 8px 5px; text-shadow: 1px 1px #009999; font-family: "palatino linotype"
- }
- table {
- font-size: 20px; padding: 20px 14px; width: 400px; border-style: inset; border-radius: 23px;
- box-shadow: 10px 10px 5px #a9a9a9; empty-cells: hide;
- }
- td {
- color: midnightblue; text-shadow: 1px 1px #009999; font-family: georgia
- }
- p {
- color: #4682b4; font-size: 18px; font-family: "palatino linotype"
- }
- </style>
- </head>
- <body>
- <h1>Weekday Calculator</h1>
- <form id="timeForm">
- <table>
- <tr>
- <td>Year:</td>
- <td width="87%"><input type="text" id="year" value="" size="4"></td>
- </tr>
- <tr>
- <td>Month:</td>
- <td><input type="text" id="month" value="" size="4"></td>
- </tr>
- <tr>
- <td>Day:</td>
- <td><input type="text" id="day" value="" size="4"></td>
- </tr>
- <tr>
- <td></td>
- </tr>
- <tr>
- <td></td>
- </tr>
- <tr>
- <td> </td>
- <td><input type="button" id="button" value="Calculate" onclick="handleInput(this.form);" ></td>
- </tr>
- </table>
- </form>
- <br>
- <p id="output"></p>
- <script language="Javascript">
- function handleInput(form) {
- try {
- var strYear = form.year.value;
- var strMonth = form.month.value;
- var strDay = form.day.value;
- var intYear = parseInt(strYear);
- var intMonth = parseInt(strMonth);
- var intDay = parseInt(strDay);
- var h = ((intDay) + Math.floor(13 * ((intMonth) + 1) / 5) + (intYear) + Math.floor((intYear)/4) - Math.floor((intYear) / 100) + Math.floor((intYear) / 400)) % 7;
- var WeekDays = ["Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"];
- var output = (WeekDays[h])
- if (isNaN(intYear))
- throw "Incorrect input. Year (" + (strYear) + ") is not a number.";
- if (intYear < 0 || intYear > 9999)
- throw "Incorrect input. Year (" + (strYear) + ") is out of expected range (0--9999).";
- if (isNaN(intMonth))
- throw "Incorrect input. Month (" + (strMonth) + ") is not a number.";
- if (intMonth < 1 || intMonth > 12)
- throw "Incorrect input. Month (" + (strMonth) + ") is out of expected range (1--12).";
- if (isNaN(intDay))
- throw "Incorrect input. Day (" + (strDay) + ") is not a number.";
- if ((intMonth) == 1, 3, 5, 7, 8, 10, 12 && ((intDay) < 1 || (intDay) > 31))
- throw "Incorrect input. Day (" + (strDay) + ") is out of expected range (1--31).";
- if ((intMonth) == 4, 6, 9, 11 && ((intDay) < 1 || (intDay) > 30))
- throw "Incorrect input. Day (" + (strDay) + ") is out of expected range (1--30).";
- if ((intMonth) == 2) {
- if (((intYear) % 4 == 0 && (intYear) % 100 != 0) || ((intYear) % 400 == 0)) {
- if ((intDay) < 1 || (intDay) > 29)
- throw "Incorrect input. Day (" + (strDay) + ") is out of expected range (1--29).";
- }
- else {
- if ((intMonth == 2) && (intDay) < 1 || (intDay) > 28)
- throw "Incorrect input. Day (" + (strDay) + ") is out of expected range (1--28).";
- }
- }
- if ((intMonth) == 1 || (intMonth)== 2) {
- intMonth = intMonth + 12;
- intYear = intYear - 1;
- }
- document.getElementById("output").innerHTML = "According to the Gregorian calender, this date is a " + output + ".";
- }
- catch (error) {
- document.getElementById("output").innerHTML = "<b> ERROR: </b>" + error;
- }
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement