How To Create Grade Solver Using JavaScript

If you are looking for a solution or an easy way to solve subject grades then you are at the right place. In this tutorial, we are going to learn on How To Create Grade Solver Using JavaScript. And using HTML forms and CSS. What does the program work? To ask the user their Full name, their subject, prelim, midterm and their end term grade. Then, click the “Compute Grade” button that our program will compute the average grade of the student. Final, our program will check your average grade to determine the student passed or failed in their subject. And, we have another one button to reset the data in the form field to have a new student or a new set of grades to compute. JavaScript This script that we need to compute the student's grade and to determine if they passed or failed in their subject.
  1. <script>
  2. var button = document.getElementsByTagName('button');
  3. button[0].onclick = solve_subject_grade;
  4. button[1].onclick = clear_text;
  5. document.onload = function() {
  6. document.getElementById('student_name').focus();
  7. };
  8. function solve_subject_grade() {
  9. var remarks;
  10. var student_name = document.getElementById("student_name").value;
  11. var subject = document.getElementById("subject").value;
  12. var prelim_grade = document.getElementById("prelim_grade").value;
  13. var midterm_grade = document.getElementById("midterm_grade").value;
  14. var endterm_grade = document.getElementById("endterm_grade").value;
  15.  
  16. var final_grade =(parseInt(prelim_grade) + parseInt(midterm_grade)+ parseInt(endterm_grade)) / 3;
  17. if (final_grade >= 75) {
  18. remarks = "<b style='color:blue;'> passed </b>";
  19. }
  20. if (final_grade <= 74) {
  21. remarks = "<b style='color:red;'> failed </b>";
  22. }
  23. if (student_name && subject && prelim_grade && midterm_grade && endterm_grade) {
  24. document.getElementById('result1').innerHTML =
  25. student_name + " your final grade in the " +subject+ " is " +
  26. "<font color='red'>"+ Math.round(final_grade,0) + "</font>.<br /><br />"+
  27. "<b class='blink_text'>You " + remarks + " the subject.</b>";
  28. } else {
  29. document.getElementById('result1').innerHTML = "<b style='color:red;'>Kindly check your details.</b>"
  30. }
  31. }
  32. function clear_text() {
  33. document.getElementById("student_name").value="";
  34. document.getElementById("subject").value="";
  35. document.getElementById("prelim_grade").value="";
  36. document.getElementById("midterm_grade").value="";
  37. document.getElementById("endterm_grade").value="";
  38. document.getElementById("student_name").focus();
  39.  
  40. }
  41. </script>
HTML This is the HTML Form Field.
  1. <table cellpadding="5" cellspacing="5">
  2. <tr>
  3. <td style="text-align:center;">Student Name</td>
  4. <td>
  5. <input type="text" style="width:250px; border:red 1px solid; background:azure; text-align:center; font-size:large; color:red;" id="student_name" autofocus>
  6. </td>
  7. </tr>
  8. <tr>
  9. <td style="text-align:center;">Subject</td>
  10. <td>
  11. <input type="text" style="width:100px; border:red 1px solid; background:azure; text-align:center; font-size:large; color:red;" id="subject">
  12. </td>
  13. </tr>
  14. <tr style="text-align:center;">
  15. <td></td>
  16. <td></td>
  17. </tr>
  18. <tr>
  19. <td style="text-align:center;">Prelim Grade</td>
  20. <td>
  21. <input type="number" step="1" min="0" style="width:100px; border:red 1px solid; background:azure; text-align:center; font-size:large; color:red;" id="prelim_grade">
  22. </td>
  23. </tr>
  24. <tr>
  25. <td style="text-align:center;">Midterm Grade</td>
  26. <td>
  27. <input type="number" step="1" min="0" style="width:100px; border:red 1px solid; background:azure; text-align:center; font-size:large; color:red;" id="midterm_grade">
  28. </td>
  29. </tr>
  30. <tr>
  31. <td style="text-align:center;">Endterm Grade</td>
  32. <td>
  33. <input type="number" step="1" min="0" style="width:100px; border:red 1px solid; background:azure; text-align:center; font-size:large; color:red;" id="endterm_grade">
  34. </td>
  35. </tr>
  36. <tr>
  37. <td colspan="2" style="text-align:center;">
  38. <br />
  39. <button style="color:red; cursor:pointer; width:100px; margin-right:40px; border-radius:4px; font-size:18px; border:blue 1px solid; background:azure; padding:10px;">
  40. Compute Grade
  41. </button>
  42. <button style="color:azure; cursor:pointer; width:100px; font-size:18px; border-radius:4px; border:red 1px solid; background:blue; padding:10px;">
  43. Another Student
  44. </button>
  45. </td>
  46. </tr>
CSS And, this is our style.
  1. <style type="text/css">
  2. body {
  3. font-family:helvitica;
  4. color:blue;
  5. font-size:18px;
  6. font-weight:bold;
  7. }
  8. label {
  9. display: table-cell;
  10. text-align: right;
  11. }
  12. input {
  13. display: table-cell;
  14. }
  15. div.row {
  16. display:table-row;
  17. }
  18.  
  19. .blink_text {
  20. -webkit-animation-name: blinker;
  21. -webkit-animation-duration: 1s;
  22. -webkit-animation-timing-function: linear;
  23. -webkit-animation-iteration-count: infinite;
  24.  
  25. -moz-animation-name: blinker;
  26. -moz-animation-duration: 1s;
  27. -moz-animation-timing-function: linear;
  28. -moz-animation-iteration-count: infinite;
  29.  
  30. animation-name: blinker;
  31. animation-duration: 1s;
  32. animation-timing-function: linear;
  33. animation-iteration-count: infinite;
  34.  
  35. color:black;
  36. }
  37.  
  38. @-moz-keyframes blinker {
  39. 0% { opacity: 1.0; }
  40. 50% { opacity: 0.0; }
  41. 100% { opacity: 1.0; }
  42. }
  43.  
  44. @-webkit-keyframes blinker {
  45. 0% { opacity: 1.0; }
  46. 50% { opacity: 0.0; }
  47. 100% { opacity: 1.0; }
  48. }
  49.  
  50. @keyframes blinker {
  51. 0% { opacity: 1.0; }
  52. 50% { opacity: 0.0; }
  53. 100% { opacity: 1.0; }
  54. }
  55. </style>
Output: This is the result if the student passed for their subject. Pass This is the result if the student failed for their subject. Failed Share us your thoughts and comments below. Thank you so much for dropping by and reading this tutorial post. For more updates, don’t hesitate and feel free to visit this website more often and please share this with your friends or email me at [email protected]. Practice Coding. Thank you very much.

Add new comment