Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,194,668 members, 7,955,418 topics. Date: Sunday, 22 September 2024 at 04:46 AM |
Nairaland Forum / Science/Technology / Programming / Please Help Debug This Javascript Program (969 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)
Please Who Can Help Me To Run Instagram Advert? / Mercedes-benz Is In Search Of Creative Programmers: #mercedesbenzchallenge / I Need Bulk Sms Unit
(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 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 8 |