Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <script type="text/javascript">
- function dispGrade() {
- var alphaResult;
- var value1 = parseInt(document.getElementById("test1").value);
- var value2 = parseInt(document.getElementById("test2").value);
- var value3 = parseInt(document.getElementById("test3").value);
- var sum = document.getElementById("sum");
- var average = document.getElementById("average");
- var alpha = document.getElementById("alpha");
- sum.value = value1 + value2 + value3;
- average.value = (sum.value/3).toFixed(2);
- var gradeResult = Math.floor(parseInt(average.value)/10);
- switch (gradeResult) {
- case 10:
- alphaResult = "A*";
- break;
- case 9:
- alphaResult = "A";
- break;
- case 8:
- alphaResult = "B";
- break;
- case 7:
- alphaResult = "C";
- case 6:
- alphaResult = "D";
- break;
- default:
- alpharesult = "F";
- break;
- }
- alpha.value = alphaResult;
- }
- </script>
- </head>
- <body>
- <form onsubmit="dispGrade()">
- <p><label for="test1">Enter your grade in test 1:</label>
- <input type="text" id="test1"></input>
- <p><label for="test2">Enter your grade in test 2:</label>
- <input type="text" id="test2"></input>
- <p><label for="test3">Enter your grade in test 3:</label>
- <input type="text" id="test3"></input>
- <p><input onclick="dispGrade(); return false;" type="submit" value="Display Computed Grades"></input>
- <div>
- <p>Sum of your average grades: <input type="text" value="" id="sum" readonly="readonly"></input>
- <p>Your average grade: <input type="text" value="" id="average" readonly="readonly"></input>
- <p>Your alpha grade: <input type="text" value="" id="alpha" readonly="readonly"></input>
- </form>
- </body>
- </html>
Add Comment
Please, Sign In to add comment