Advertisement
Guest User

Untitled

a guest
Sep 25th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 KB | None | 0 0
  1.  
  2. <html>
  3.  
  4. <head>
  5.  
  6. <meta name="group" content="116">
  7. <meta name="author" content="Michaela Stenljung" "Jakob Hoverbrant">
  8.  
  9. <title>Weekday Calculator</title>
  10. <style>
  11.  
  12. body {
  13. background-color: #f5f5f5; border-style: outset;
  14. }
  15.  
  16. h1 {
  17. font-size: 275%; color: #171769; padding: 8px 5px; text-shadow: 1px 1px #009999; font-family: "palatino linotype"
  18. }
  19.  
  20. table {
  21. font-size: 20px; padding: 20px 14px; width: 400px; border-style: inset; border-radius: 23px;
  22. box-shadow: 10px 10px 5px #a9a9a9; empty-cells: hide;
  23. }
  24.  
  25. td {
  26. color: midnightblue; text-shadow: 1px 1px #009999; font-family: georgia
  27. }
  28.  
  29. p {
  30. color: #4682b4; font-size: 18px; font-family: "palatino linotype"
  31. }
  32.  
  33.  
  34. </style>
  35.  
  36. </head>
  37.  
  38. <body>
  39.  
  40.  
  41. <h1>Weekday Calculator</h1>
  42.  
  43.  
  44.  
  45.  
  46. <form id="timeForm">
  47.  
  48. <table>
  49.  
  50.  
  51. <tr>
  52. <td>Year:</td>
  53. <td width="87%"><input type="text" id="year" value="" size="4"></td>
  54. </tr>
  55.  
  56. <tr>
  57. <td>Month:</td>
  58. <td><input type="text" id="month" value="" size="4"></td>
  59. </tr>
  60.  
  61. <tr>
  62. <td>Day:</td>
  63. <td><input type="text" id="day" value="" size="4"></td>
  64. </tr>
  65.  
  66. <tr>
  67. <td></td>
  68. </tr>
  69.  
  70. <tr>
  71. <td></td>
  72. </tr>
  73.  
  74. <tr>
  75. <td>&nbsp;</td>
  76. <td><input type="button" id="button" value="Calculate" onclick="handleInput(this.form);" ></td>
  77. </tr>
  78.  
  79.  
  80. </table>
  81.  
  82. </form>
  83.  
  84. <br>
  85.  
  86. <p id="output"></p>
  87.  
  88.  
  89. <script language="Javascript">
  90.  
  91. function handleInput(form) {
  92. try {
  93. var strYear = form.year.value;
  94. var strMonth = form.month.value;
  95. var strDay = form.day.value;
  96.  
  97. var intYear = parseInt(strYear);
  98. var intMonth = parseInt(strMonth);
  99. var intDay = parseInt(strDay);
  100.  
  101. var h = ((intDay) + Math.floor(13 * ((intMonth) + 1) / 5) + (intYear) + Math.floor((intYear)/4) - Math.floor((intYear) / 100) + Math.floor((intYear) / 400)) % 7;
  102. var WeekDays = ["Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"];
  103. var output = (WeekDays[h])
  104.  
  105.  
  106. if (isNaN(intYear))
  107. throw "Incorrect input. Year (" + (strYear) + ") is not a number.";
  108. if (intYear < 0 || intYear > 9999)
  109. throw "Incorrect input. Year (" + (strYear) + ") is out of expected range (0--9999).";
  110.  
  111. if (isNaN(intMonth))
  112. throw "Incorrect input. Month (" + (strMonth) + ") is not a number.";
  113. if (intMonth < 1 || intMonth > 12)
  114. throw "Incorrect input. Month (" + (strMonth) + ") is out of expected range (1--12).";
  115.  
  116. if (isNaN(intDay))
  117. throw "Incorrect input. Day (" + (strDay) + ") is not a number.";
  118.  
  119.  
  120.  
  121.  
  122. if ((intMonth) == 1, 3, 5, 7, 8, 10, 12 && ((intDay) < 1 || (intDay) > 31))
  123. throw "Incorrect input. Day (" + (strDay) + ") is out of expected range (1--31).";
  124.  
  125. if ((intMonth) == 4, 6, 9, 11 && ((intDay) < 1 || (intDay) > 30))
  126. throw "Incorrect input. Day (" + (strDay) + ") is out of expected range (1--30).";
  127.  
  128.  
  129.  
  130. if ((intMonth) == 2) {
  131. if (((intYear) % 4 == 0 && (intYear) % 100 != 0) || ((intYear) % 400 == 0)) {
  132. if ((intDay) < 1 || (intDay) > 29)
  133. throw "Incorrect input. Day (" + (strDay) + ") is out of expected range (1--29).";
  134. }
  135. else {
  136. if ((intMonth == 2) && (intDay) < 1 || (intDay) > 28)
  137. throw "Incorrect input. Day (" + (strDay) + ") is out of expected range (1--28).";
  138. }
  139. }
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146. if ((intMonth) == 1 || (intMonth)== 2) {
  147. intMonth = intMonth + 12;
  148. intYear = intYear - 1;
  149. }
  150.  
  151.  
  152.  
  153.  
  154. document.getElementById("output").innerHTML = "According to the Gregorian calender, this date is a " + output + ".";
  155.  
  156. }
  157.  
  158. catch (error) {
  159. document.getElementById("output").innerHTML = "<b> ERROR: </b>" + error;
  160. }
  161. }
  162. </script>
  163.  
  164.  
  165.  
  166. </body>
  167.  
  168. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement