₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,051 members, 8,420,069 topics. Date: Thursday, 04 June 2026 at 10:38 AM

Toggle theme

Please Help Debug This Javascript Program - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingPlease 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
1 Reply

Am Stucked In Writing A Javascript ProgramNeed Help With This JavascriptDebug This Code At Your Spare Time.234

Mobile App Development: How Much It Costs In NigeriaTop IDE For C++ Developershow to become a programmer