Monday, March 26, 2012

JavaScript issues, care to help?

This Javascript is giving me a headache,It's due in an hours time but can't seem to finish.
somebody help me out by either debugging or sharing with a friend who might be in the light of js (javascript)
I know it's a minor thing that's refusing to work but i'm drained out kabisa for now..... comment on the post anything you think can help me. thanks

here is my code
------------------------------------------------------------------

//function start is called when the start button is clicked on the page
function start(){
document.write("
Course grades ");
document.write("
course " + " grade " + " hours " );
subjects = prompt ("How many subjects?");
var i = 0;
while (i
var input=prompt("Enter Course Name, Grade and credit hours as shown in the text field below of click okay with no data to terminate.","Course/Grade/Credit hours");
if (input!=null && input!=" "){
var mySplitResult = input.split("/"); // splits the input using by the '/' positions
//assigning slit elements to variables
var course = mySplitResult[0];
var grade = mySplitResult[1];
var hours = mySplitResult[2];
document.write("
" + course + " " + grade + " " + hours );

//new variables to help calculate totals
var totalhours= +hours;

var gradepoints;
var sumpoints=0;
// conditions for calculating points according to the grade
var multiplier;
if (grade=='A' || grade =='a'){ multiplier=4;}
if (grade=='B+'|| grade =='b+'){ multiplier=3.5;}
if (grade=='B' || grade =='b'){ multiplier=3;}
if (grade=='C+'|| grade =='c+'){ multiplier=2.5;}
if (grade=='C' || grade =='c'){ multiplier=2;}
if (grade=='D' || grade =='d'){multiplier=1;}
if (grade=='F' || grade=='AF' ||grade=='WF' ||grade=='f' || grade=='af' ||grade=='wf' ){
multiplier=0;}
gradepoints= hours*multiplier;
}
var sumpoints= sumpoints+gradepoints;

i++;
}
var avpoints = sumpoints/hours;
var credithours= +hours;
var sumpoints_courses;
var GPA=sumpoints/credithours;
// outputs the course grades, gpa, total points
document.write("

total points are " + sumpoints);
document.write("
" + "number of hours = " + totalhours );
document.write("
and your GPA = " + avpoints);
document.write("");
}// end of function start


The Problem
After clicking the start button, you're asked to say the number of subjects you should input- good
It prompts you for the 5 subjects to be entered in the format 'Course/Grade/Credit hours'- good

after doing that It's supposed to compute the totals of all the subjects you entered, unfortunately it only does the computation of the last subject, care to help?






Here is an extract of the que,

Once the course grades have been stored, the page should compute the student's overall GPA. According to the XYZ University Bulletin, grade point averages are computed as follows:
1. Grade points (a.k.a. quality points) are assigned to each course based on the grade and number of credit hours:
  • A yields 4 points for each hour
  • B+ yields 3.5 points for each hour
  • B yields 3 points for each hour
  • C+ yields 2.5 points for each hour
  • C yields 2 points for each hour
  • D yields 1 point for each hour
  • F, AF, and WF yield 0 points for each hour
2. The grade point average (a.k.a. quality point average) is computed by dividing the total number of grade points earned by the total number of credit hours.
For example, suppose a student entered the following course information (with each line entered in a different dialog box):
THL100 B+ 3
PHL107 A 3
ENG120 C+ 3
MTH245 A 4
CSC221 A 3
The total number of grade points earned by this student is
(3.5 * 3) + (4 * 3) + (2.5 * 3) + (4 * 4) + (4 * 3) =
10.5 + 12 + 7.5 + 16 + 12 =
58
Dividing this total by the number of credit hours completed yields a GPA of 58/16 = 3.625.
Your page should display the total number of grade points, number or hours, and GPA, as well as all of the course information in a readable form. This information should not be displayed in the page until all user input has been processed. For example,

COURSE GRADE HOURS
THL100 B+ 3
PHL107 A 3
ENG120 C+ 3
MTH245 A 4
CSC221 A 3
Total grade points = 58
Number of hours = 16
GPA = 3.625

No comments:

Post a Comment