Skip to content

Instantly share code, notes, and snippets.

@tomily1
Forked from andrewjkerr/GradeCalculator.js
Created November 2, 2016 12:47
Show Gist options
  • Save tomily1/0f8c1336e538b8077b2177db2cb5975f to your computer and use it in GitHub Desktop.
Save tomily1/0f8c1336e538b8077b2177db2cb5975f to your computer and use it in GitHub Desktop.
A simple grade calculator script written in JavaScript along with the HTML form. The script uses the grading scale from my Marketing class, but you can change it to whatever is needed. Something important to note is that this grade calculator just adds everything up and uses a point scale. --- There's an implementation for my Marketing and Digit…
<script>
function setGrades() {
// Define those variables!
var quiz1 = parseFloat(document.getElementById('quiz1').value);
var quiz2 = parseFloat(document.getElementById('quiz2').value);
var quiz3 = parseFloat(document.getElementById('quiz3').value);
var quiz4 = parseFloat(document.getElementById('quiz4').value);
var quiz5 = parseFloat(document.getElementById('quiz5').value);
var quiz6 = parseFloat(document.getElementById('quiz6').value);
var quiz7 = parseFloat(document.getElementById('quiz7').value);
var quiz8 = parseFloat(document.getElementById('quiz8').value);
var quiz9 = parseFloat(document.getElementById('quiz9').value);
var quiz10 = parseFloat(document.getElementById('quiz10').value);
var exam1 = parseFloat(document.getElementById('exam1').value);
var exam2 = parseFloat(document.getElementById('exam2').value);
var exam3 = parseFloat(document.getElementById('exam3').value);
var extra = parseFloat(document.getElementById('extra').value);
// Calculate the total points earned!
var totalPoints = quiz1 + quiz2 + quiz3 + quiz4 + quiz5 + quiz6 + quiz7 + quiz8 + quiz9 + quiz10 + exam1 + exam2 + exam3 + extra;
document.getElementById('total').value = totalPoints;
// Select letter grade!
if(totalPoints >= 184){
document.getElementById('letter').value = "A";
}
else if(183 >= totalPoints && totalPoints >= 178){
document.getElementById('letter').value = "A-";
}
else if(177 >= totalPoints && totalPoints >= 172){
document.getElementById('letter').value = "B+";
}
else if(171 >= totalPoints && totalPoints >= 164){
document.getElementById('letter').value = "B";
}
else if(163 >= totalPoints && totalPoints >= 158){
document.getElementById('letter').value = "B-";
}
else if(157 >= totalPoints && totalPoints >= 152){
document.getElementById('letter').value = "C+";
}
else if(151 >= totalPoints && totalPoints >= 144){
document.getElementById('letter').value = "C";
}
else if(143 >= totalPoints && totalPoints >= 138){
document.getElementById('letter').value = "C-";
}
else if(137 >= totalPoints && totalPoints >= 132){
document.getElementById('letter').value = "D+";
}
else if(131 >= totalPoints && totalPoints >= 124){
document.getElementById('letter').value = "D";
}
else if(123 >= totalPoints && totalPoints >= 118){
document.getElementById('letter').value = "D-";
}
else{
document.getElementById('letter').value = "E";
}
}
</script>
<p><u>QUIZZES (//OUT OF TWO)</u></p>
<p>
<p>Quiz 1: <input text='text' id='quiz1' value='0' onkeyup='setGrades();' /> Quiz 2: <input text='text' id='quiz2' value='0' onkeyup='setGrades();' /> Quiz 3: <input text='text' id='quiz3' value='0' onkeyup='setGrades();' /></p>
<p>Quiz 4: <input text='text' id='quiz4' value='0' onkeyup='setGrades();' /> Quiz 5: <input text='text' id='quiz5' value='0' onkeyup='setGrades();' /> Quiz 6: <input text='text' id='quiz6' value='0' onkeyup='setGrades();' /></p>
<p>Quiz 7: <input text='text' id='quiz7' value='0' onkeyup='setGrades();' /> Quiz 8: <input text='text' id='quiz8' value='0' onkeyup='setGrades();' /> Quiz 9: <input text='text' id='quiz9' value='0' onkeyup='setGrades();' /></p>
<p>Quiz 10: <input text='text' id='quiz10' value='0' onkeyup='setGrades();' /></p>
</p>
<p><u>EXAMS (//OUT OF SIXTY)</u></p>
<p>
<p>Exam 1: <input text='text' id='exam1' value='0' onkeyup='setGrades();' /> Exam 2: <input text='text' id='exam2' value='0' onkeyup='setGrades();' /> Exam 3: <input text='text' id='exam3' value='0' onkeyup='setGrades();' /></p>
</p>
<p><u>EXTRA CREDIT (//UP TO FIVE POINTS)</u></p>
<p>
<p>Extra Credit Earned: <input text='text' id='extra' value='0' onkeyup='setGrades();' /></p>
</p>
<p><u>FINAL GRADE</u></p>
<p>
<p>TOTAL POINTS: <input type='text' id='total' value='0' /></p>
<p>LETTER GRADE: <input type='text' id='letter' value='E' /></p>
</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment