WK_of_Angmar

Reddit - redditsheep3

Aug 4th, 2012
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.64 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script type="text/javascript">
  5. function dispGrade() {
  6.     var alphaResult;
  7.     var value1 = parseInt(document.getElementById("test1").value);
  8.     var value2 = parseInt(document.getElementById("test2").value);
  9.     var value3 = parseInt(document.getElementById("test3").value);
  10.     var sum = document.getElementById("sum");
  11.     var average = document.getElementById("average");
  12.     var alpha = document.getElementById("alpha");
  13.     sum.value = value1 + value2 + value3;
  14.     average.value = (sum.value/3).toFixed(2);
  15.     var gradeResult = Math.floor(parseInt(average.value)/10);
  16.     switch (gradeResult) {
  17.         case 10:
  18.         alphaResult = "A*";
  19.         break;
  20.         case 9:
  21.         alphaResult = "A";
  22.         break;
  23.         case 8:
  24.         alphaResult = "B";
  25.         break;
  26.         case 7:
  27.         alphaResult = "C";
  28.         case 6:
  29.         alphaResult = "D";
  30.         break;
  31.         default:
  32.         alpharesult = "F";
  33.         break;
  34.     }
  35.     alpha.value = alphaResult;
  36. }
  37. </script>
  38. </head>
  39. <body>
  40. <form onsubmit="dispGrade()">
  41. <p><label for="test1">Enter your grade in test 1:</label>
  42. <input type="text" id="test1"></input>
  43. <p><label for="test2">Enter your grade in test 2:</label>
  44. <input type="text" id="test2"></input>
  45. <p><label for="test3">Enter your grade in test 3:</label>
  46. <input type="text" id="test3"></input>
  47. <p><input onclick="dispGrade(); return false;" type="submit" value="Display Computed Grades"></input>
  48. <div>
  49. <p>Sum of your average grades: <input type="text" value="" id="sum" readonly="readonly"></input>
  50. <p>Your average grade: <input type="text" value="" id="average" readonly="readonly"></input>
  51. <p>Your alpha grade: <input type="text" value="" id="alpha" readonly="readonly"></input>
  52. </form>
  53. </body>
  54. </html>
Add Comment
Please, Sign In to add comment