I created a JavaScript function that should display a letter grade once the average of 5 subjects is calculated, but for some reason, it's not working as expected. I'm feeling quite lost at the moment.
The fourth function I implemented isn't generating any letter grades. Apart from this issue, I believe everything else in my code is correct.
function getHandleValue(idName) {
const value = parseInt(document.getElementById(idName).value);
console.log(value);
return value;
}
function getTotal() {
//console.log("app js starts loading")
let english = getHandleValue('english');
let math = getHandleValue('math');
let physics = getHandleValue('physics');
let computer = getHandleValue('computer');
let science = getHandleValue('science');
//console.log("app js ends loading")
let total = english + math + physics + computer + science;
document.getElementById('total').innerHTML = total;
return total;
}
function getAverage() {
// option 1
// const total = parseInt(document.getElementById('total').innerHTML);
// const average = total / 5;
// document.getElementById('average').innerHTML = average;
// option 2
const average = getTotal() / 5;
document.getElementById('average').innerHTML = average;
}
function letterGrade() {
letterGrade;
if (grade >= 90 && grade <= 100)
letterGrade = 'A';
else if (grade >= 80 && grade <= 89)
letterGrade = 'B';
else if (grade >= 70 && grade <= 79)
letterGrade = 'C';
else if (grade >= 60 && grade <= 69)
letterGrade = 'D';
else if (grade > 1 && grade <= 59)
letterGrade = 'F';
let average = letterGrade;
document.getElementById('Grade').innerHTML = Grade;
}