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

# Thread: GPA calculator practice exam

1. ## GPA calculator practice exam

I must be misunderstanding a fundamental aspect of javascript because I have been sitting here scratching my head for an hour trying to figure out why my code produces a nAn for the gpa calculation. I intended the calcutator to erase any entries that are not standard grades, and prompt the user to fill in blanks if there are any. I apologize if the code is too long. I think there is a probably a way to cut it down, so if someone could tell me how that would also be extremely helpful.

P.S. the calculator is supposed to convert the letter grade to the gpa score (A-->4.0) so if someone could explain how it would be done in an array instead that would help. I tried to do it, but I couldn't get that to work. This way is functional albeit long.

My main issue is the calculator's inability to calculate!
Thank you for any responses.
I cannot attach anything so I will include a pastebin link instead:
http://pastebin.com/DfyR46p2

• This is not the final solution to your problem (it's late here and I'm going to bed)
but, it should reduce possible syntax errors in your very lengthly code
if you understand what it is doing.
Code:
```<script type="text/javascript">

var grade = '';
case 'A':  grade = 4.0; break;
case 'A-': grade = 3.7; break;
case 'B+': grade = 3.5; break;
case 'B':  grade = 3.0; break;
case 'B-': grade = 2.7; break;
case 'C+': grade = 2.3; break;
case 'C':  grade = 2.0; break;
case 'C-': grade = 1.7; break;
case 'D+': grade = 1.3; break;
case 'D':  grade = 1.0; break;
case 'D-': grade = 0.7; break;
case 'F':  grade = 0.0; break;
default:  alert('Invalid entry'); break;
}
}
var total = 0;
if (total != 0) { total = total/5; } else { total = 0; }
}
var grade1 = 'A';
var grade2 = 'B';
var grade3 = 'C';
var grade4 = 'B';
var grade5 = 'A';

</script>```

•

#### Posting Permissions

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