It cannot work as you have a syntax error:-
while(counterGrade
<i= )
The default of all your promts is undefined.
semester=prompt("Please enter the semester you would like to calculate your GPA for."
, "" );
When you declare a variable with var you wipe out any previous instance of it:-
function ConvertGradeToPoints(grade) {
var grade;
A prompt dialog can only return a single value., that is the value entered by the user.
numCredits=GetValidNumberInput("How many credits is " + className[counterCredits] + " class worth?",
1,4)
Here you have assigned "1" as the default value. The correct way is something like:-
numCredits= prompt("How many credits is " + className[counterCredits] + " class worth?","");
You must check on the validity of that value in script:-
checkValidInput(numCredits); // function checkValidInputs checks for a number within a valid range.
You have declared your array with a length of i, which has a value of 0.
var className = new Array(
i);
There are probably other errors as well.
Other comments:
You have omitted the ; at the line ends in many places. It is true that the ; is not mandatory, but if you make a habit of leaving it out you will run into trouble one day.
You should place the opening brace { on the
same line as the if/else/while/do/function statement, not the next line. Again, you will run into trouble if you do not follow this advice (we had a case only the other day in this forum).
Simplify your grades>points calculation:-
Code:
grade = grade.toLowerCase();
var gradeslist = ["a","b","c","d","e"]
var pointslist = [4,3,2,1,0]
for (var i =0; i<gradeslist.length; i++) {
if (gradeslist[i] == grade) {
points = pointslist[i];
}
}
Fix these errors/infelicities, try inserting some alerts at strategic positions to check on the values of your variables. If it still does not work then come back. But please see Forum Rule 1.5 re homework.
BTW, when posting here please follow the posting guidelines and wrap your code in CODE tags. This means use the octothorpe or # button on the toolbar. You can (and should) edit your previous post.