Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 2,931,669 members, 7,089,684 topics. Date: Tuesday, 27 September 2022 at 08:26 AM

Please Help Debug This Javascript Program - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Please Help Debug This Javascript Program (904 Views)

Am Stucked In Writing A Javascript Program / Need Help With This Javascript / Debug This Code At Your Spare Time. (2) (3) (4)

(1) (Reply)

Please Help Debug This Javascript Program by Aybee92(m): 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)

I Need Bulk Sms Unit / Automation Testing – Best Open Source Tools For Mobile Apps / Get High Paying Freelance IT Jobs

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2022 Oluwaseun Osewa. All rights reserved. See How To Advertise. 30
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.