...

View Full Version : Letter To Number



johfarrar
12-17-2002, 08:55 PM
I need a way to convert input into a number. I have a function that doesn't work. Please help.


function totalPoints() {
var points = 0;
for (i=1; 8 >= i; i++) {
var x = document.forms[i].grade.value;
if ((x == "a") || (x == "A")) {
eval(points + 4);
}
else {
if ((x == "b") || (x == "B")) {
eval(points + 3);
}
else {
if ((x == "c") || (x == "C")) {
eval(points + 2);
}
else {
if ((x == "d") || (x == "D")) {
eval(points + 1);
}
else {
if ((x == "f") || (x == "F")) {
eval(points + 0);
}
}
}
}
}
}
return points;
}

ConfusedOfLife
12-17-2002, 09:03 PM
Put a good description of your problem in the title that ppl understand your question.
Also what kinda number do you wana make? Does it have a special order or what?

johfarrar
12-17-2002, 09:12 PM
Sorry ... it was the second time I typed it in and was kind of frustrated that it didn't take the first time.

It's going to be A = 4, B = 3, C = 2, D = 1, F = 0. It's for a GPA script I'm writing. I know there are some out there, but I would like to do one myself.

Skyzyx
12-17-2002, 10:13 PM
I think I might have something... but real quick: Are you using 8 separate forms for inputting the grades? I'd like to know, as I usually create a webpage to try it all out to make sure it works before I post anything...

beetle
12-17-2002, 10:43 PM
I'll let you or someone else handle the input, but here's a better algorithm for getting the sum.
switch (x.toUpperCase()) {
case 'A': points++;
case 'B': points++;
case 'C': points++;
case 'D': points++;
case 'F': break;
default : alert("The grade '" + x + "' is not valid");
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum