• We just launched and are currently in beta. Join us as we build and grow the community.

How To Create Grade Solver Using JavaScript

Bibstee

Crypto Analyst
B Rep
0
0
0
Rep
0
B Vouches
0
0
0
Vouches
0
Posts
162
Likes
166
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
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. var

    final_grade =

    (

    parseInt(

    prelim_grade)

    +

    parseInt(

    midterm_grade)

    +

    parseInt(

    endterm_grade)

    )

    /

    3

    ;
  16. if

    (

    final_grade >=

    75

    )

    {
  17. remarks =

    "<b style='color:blue;'> passed </b>"

    ;
  18. }
  19. if

    (

    final_grade <=

    74

    )

    {
  20. remarks =

    "<b style='color:red;'> failed </b>"

    ;
  21. }
  22. if

    (

    student_name &&

    subject &&

    prelim_grade &&

    midterm_grade &&

    endterm_grade)

    {
  23. document.getElementById

    (

    'result1'

    )

    .innerHTML

    =
  24. student_name +

    " your final grade in the "

    +

    subject+

    " is "

    +
  25. "<font color='red'>"

    +

    Math

    .round

    (

    final_grade,

    0

    )

    +

    "</font>.<br /><br />"

    +
  26. "<b class='blink_text'>You "

    +

    remarks +

    " the subject.</b>"

    ;
  27. }

    else

    {
  28. document.getElementById

    (

    'result1'

    )

    .innerHTML

    =

    "<b style='color:red;'>Kindly check your details.</b>"
  29. }
  30. }
  31. function

    clear_text(

    )

    {
  32. document.getElementById

    (

    "student_name"

    )

    .value

    =

    ""

    ;
  33. document.getElementById

    (

    "subject"

    )

    .value

    =

    ""

    ;
  34. document.getElementById

    (

    "prelim_grade"

    )

    .value

    =

    ""

    ;
  35. document.getElementById

    (

    "midterm_grade"

    )

    .value

    =

    ""

    ;
  36. document.getElementById

    (

    "endterm_grade"

    )

    .value

    =

    ""

    ;
  37. document.getElementById

    (

    "student_name"

    )

    .focus

    (

    )

    ;

  38. }
  39. </

    script>

HTML

This is the HTML Form Field.

  1. <center

    >
  2. <table

    cellpadding

    =

    "5"

    cellspacing

    =

    "5"

    >
  3. <tr

    >
  4. <td

    style

    =

    "text-align:center;"

    >

    Student Name</

    td

    >
  5. <td

    >
  6. <input

    type

    =

    "text"

    style

    =

    "width:250px; border:red 1px solid; background:azure; text-align:center; font-size:large; color:red;"

    id

    =

    "student_name"

    autofocus>
  7. </

    td

    >
  8. </

    tr

    >
  9. <tr

    >
  10. <td

    style

    =

    "text-align:center;"

    >

    Subject</

    td

    >
  11. <td

    >
  12. <input

    type

    =

    "text"

    style

    =

    "width:100px; border:red 1px solid; background:azure; text-align:center; font-size:large; color:red;"

    id

    =

    "subject"

    >
  13. </

    td

    >
  14. </

    tr

    >
  15. <tr

    style

    =

    "text-align:center;"

    >
  16. <td

    ></

    td

    >
  17. <td

    ></

    td

    >
  18. </

    tr

    >
  19. <tr

    >
  20. <td

    style

    =

    "text-align:center;"

    >

    Prelim Grade</

    td

    >
  21. <td

    >
  22. <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"

    >
  23. </

    td

    >
  24. </

    tr

    >
  25. <tr

    >
  26. <td

    style

    =

    "text-align:center;"

    >

    Midterm Grade</

    td

    >
  27. <td

    >
  28. <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"

    >
  29. </

    td

    >
  30. </

    tr

    >
  31. <tr

    >
  32. <td

    style

    =

    "text-align:center;"

    >

    Endterm Grade</

    td

    >
  33. <td

    >
  34. <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"

    >
  35. </

    td

    >
  36. </

    tr

    >
  37. <tr

    >
  38. <td

    colspan

    =

    "2"

    style

    =

    "text-align:center;"

    >
  39. <br

    /

    >
  40. <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;"

    >
  41. Compute Grade
  42. </

    button

    >
  43. <button

    style

    =

    "color:azure; cursor:pointer; width:100px; font-size:18px; border-radius:4px; border:red 1px solid; background:blue; padding:10px;"

    >
  44. Another Student
  45. </

    button

    >
  46. </

    td

    >
  47. </

    tr

    >
  48. </

    table

    >
  49. </

    center

    >

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. .blink_text

    {
  19. -webkit-animation-name:

    blinker;
  20. -webkit-animation-duration:

    1s

    ;
  21. -webkit-animation-timing-function:

    linear;
  22. -webkit-animation-iteration-count:

    infinite

    ;

  23. -moz-animation-name:

    blinker;
  24. -moz-animation-duration:

    1s

    ;
  25. -moz-animation-timing-function:

    linear;
  26. -moz-animation-iteration-count:

    infinite

    ;

  27. animation-name

    :

    blinker;
  28. animation-duration

    :

    1s

    ;
  29. animation-timing-function

    :

    linear;
  30. animation-iteration-count

    :

    infinite

    ;

  31. color

    :

    black

    ;
  32. }

  33. @-moz-keyframes

    blinker {
  34. 0%

    {

    opacity

    :

    1.0

    ;

    }
  35. 50%

    {

    opacity

    :

    0.0

    ;

    }
  36. 100%

    {

    opacity

    :

    1.0

    ;

    }
  37. }

  38. @-webkit-keyframes

    blinker {
  39. 0%

    {

    opacity

    :

    1.0

    ;

    }
  40. 50%

    {

    opacity

    :

    0.0

    ;

    }
  41. 100%

    {

    opacity

    :

    1.0

    ;

    }
  42. }

  43. @keyframes

    blinker {
  44. 0%

    {

    opacity

    :

    1.0

    ;

    }
  45. 50%

    {

    opacity

    :

    0.0

    ;

    }
  46. 100%

    {

    opacity

    :

    1.0

    ;

    }
  47. }
  48. </style>

Output:

This is the result if the student passed for their subject.

passed_0.png


This is the result if the student failed for their subject.

failed.png


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.


Download
You must upgrade your account or reply in the thread to view hidden text.
 

452,292

323,341

323,350

Top