/    Sign up×
Community /Pin to ProfileBookmark

I need Help. How do you create a GPA calculator? Somebody please help me!

I am having trouble getting my functions to work properly. the requirements for my web page are to create a webpage that allows the user to enter a class name, their “grade” and number of credits per class. Allow the user to enter up to 5 classes. You may allow the user to enter more classes if you wish. When determining GPA for a semester A’s are worth 4 points, B’s are worth 3 points, C’s are worth 2 points, D’s are worth 1 point, and F’s are worth 0 points. To determine your GPA for the semester multiply the number of credits for each class times your grade (0-4); this gives you your honor points for each class. Add up the honor points for each class and divide by the total number of credits. For example, a student that takes 2 classes and earns a 3 credit B ( 9 honor points – 3 * 3)and a 4 credit A (16 honor points – 4 * 4) will have a semester GPA of 3.5714…(25 honor points / 7 total credits).

The user will enter 0 through 4 for the grade, but the web page should mention what needs to be entered. Meaning, tell the user to enter 4 for an A, 3 for a B, 2 for a C, 1 for a D, and 0 for an F.

Have a button initiate an action that calculates and displays the students GPA for the semester.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Major_PayneDec 12.2008 — Actually, if you Google for GPA Calculator scripts, you'll find a lot of those already done. They range from very basic to nice GPA Calculators. Might look at the code on those to get some idea how to set yours up.
Copy linkTweet thisAlerts:
@ppotterDec 14.2008 — I have something sorta similar. Maybe you can get some ideas from it.


[CODE]
<html>
<!-- This page utilizes the ParseArray function to store an array of numbers and -->
<!-- compute their average. This page also determines the category average by -->
<!-- converting each sequence of grades to an array of numbers and then calling the -->
<!-- Average function on those arrays. -->
<!-- ================================================================================== ––>

<head>
<title> Grade Calculator </title>
<style type="text/css">
.style1 {
width: 207px;
height: 23px;
margin-left: 0px;
margin-top: 0px;
}
</style>
<h1 style="font-family: 'Comic Sans MS'; font-size: xx-large; color: #800000"> Grade Calculator </h1>

<script type="text/javascript" src="array.js"></script>


<script type="text/javascript">
function Average(numArray)
// Assumes: numArray is an array of numbers
// Returns: average of the numbers in numArray
{
var sum, index;

sum = 0; // INITIALIZE sum

index = 0; // START AT FIRST NUMBER
while (index < numArray.length) { // AS LONG AS NUMBERS LEFT
sum = sum + numArray[index]; // ADD NUMBER TO sum
index = index + 1;
}
return sum/numArray.length; // RETURN AVERAGE

}

function ShowAvg()
// Assumes: Anything with Box at the end contains a sequence of numbers
// Results: writes the average to avgBox
{
var hw1, lb2, mt3, fl4, hw1Array, lb2Array, num1Array, num2Array, Avg, letterGrade;

/* alert("in function") TESTING PURPOSE ONLY */

hw1 = document.getElementById("hw1Box").value; // ASSIGNED TO VARIABLE
lb2 = document.getElementById("lb2Box").value;
mt3 = document.getElementById("mt3Box").value;
fl4 = document.getElementById("fl4Box").value;

hw1Array = hw1.split(/[, tn]+/); // SPLIT EACH LIST INTO AN ARRAY
lb2Array = lb2.split(/[, tn]+/);

num1Array = ParseArray(hw1Array); // PARSE EACH ARRAY
num2Array = ParseArray(lb2Array);
mt3 = parseFloat(mt3); // PARSEFLOAT THE VARIBLES CONTAINING MIDTERM AND FINAL GRADE
fl4 = parseFloat(fl4);

num1 = Average(num1Array);
num2 = Average(num2Array);


Avg = num1*0.25 + num2*0.20 + mt3*0.25 + fl4*0.30; // AVERAGE COMPUTATION
document.getElementById('AverageBox').value = Avg;


if (Avg >= 90) {
letterGrade = "A";
}
else if (Avg >= 80) {
letterGrade = "B";
}
else if (Avg >= 70) {
letterGrade = "C";
}
else if (Avg >= 60) {
letterGrade = "D";
}
else {
letterGrade = "F";
}
document.getElementById('letterGradeBox').value = letterGrade;
}
</script>
</head>

<body background="Images/stars2.gif">
<p>
Homework grades: <input type="text" id="hw1Box" size="40" value="0" />
<br /><br />
Lab grades: <input type="text" id="lb2Box" size="40" value="0" />
<br /><br />
Midterm exam: <input type="text" id="mt3Box" size="3" value="0" />
<br /><br />
Final exam: <input type="text" id="fl4Box" size="3" value="0" />
<br /><br />
<input type="button" value="" onclick="ShowAvg();"
style="background-image: url('Images/2Button.jpg')" class="style1" />

<br /><br />
Final course average: <input type="text" id="AverageBox" size="8" value="0" />
<br /><br />
You are guaranteed: <input type="text" id="letterGradeBox" size="3" value="0" />
</p>
</body>
</html>

[/CODE]


All you really have to do is change the values under (Avg). But this will calculate the grade and give a letter. For the most part you can make it a GPA if you change somethings.

I also attached an array.js file, if you needed an idea.
×

Success!

Help @ryhorn_25 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...