Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

1. ## Letter To Number

I need a way to convert input into a number. I have a function that doesn't work. Please help.

Code:
```function totalPoints() {
var points = 0;
for (i=1; 8 >= i; i++) {
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;
}```

• 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?

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

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

• I'll let you or someone else handle the input, but here's a better algorithm for getting the sum.
Code:
```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");
}```

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•