Please Help Debug This Javascript Program - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › Please Help Debug This Javascript Program (1030 Views)
1 Reply
| Please Help Debug This Javascript Program by Aybee92(op): 9:15am On Apr 27, 2017 |
am trying to write a GPA calculator. the code runs but i dont get d expected output. what could be wrong with my code pls here is d code below /*GPA calculator*/ //variable declaration var courseTitle, numberOfCoursesOffered, grade, iGrade, courseUnit, totalCourseUnit, result, GPA; //variable initialisation var a = 5, b = 4, c = 3, d = 2, f = 0; result = 0; totalCourseUnit = 0; courseTitle = []; numberOfCoursesOffered = parseInt(prompt('How many courses are you offering this semester? ')); courseTitle.push(prompt('Please enter your first course title ')); grade = prompt('enter grade '); courseUnit = parseInt(prompt('enter course unit')); for(var i = 1; i < numberOfCoursesOffered; i++){ totalCourseUnit += courseUnit; if(grade == 'a' || grade == 'A' ){ iGrade = a; }else if(grade == 'b' || grade == 'B'){ iGrade = b; }else if(grade == 'c' || grade == 'C'){ iGrade = c; }else if(grade == 'd' || grade == 'D'){ iGrade = d; }else{ iGrade = f; } result += (iGrade * courseUnit); courseTitle.push(prompt('Please enter your next course title ')); grade = prompt('enter next grade'); courseUnit = parseInt(prompt('enter next course unit')); } GPA = (result / totalCourseUnit); document.write('The number of courses you took this semester is ' + numberOfCoursesOffered + '<br/>'); document.write('with the total credit unit of : ' + totalCourseUnit + '<br/>'); document.write('your grade point is : ' + GPA); |
| Re: Please Help Debug This Javascript Program by hollyfat(m): 9:48pm On Apr 27, 2017 |
Value of iGrade should be number and not test. You can't divide string with integer |
Am Stucked In Writing A Javascript Program • Need Help With This Javascript • Debug This Code At Your Spare Time. • 2 • 3 • 4
Mobile App Development: How Much It Costs In Nigeria • Top IDE For C++ Developers • how to become a programmer