Question
I neeed help with my HTML code, I wrote a code but I can't seem to find where I did it wrong. I emailed it
I neeed help with my HTML code,
I wrote a code but I can't seem to find where I did it wrong. I emailed it in and the professor said that it wasn't what the assignment was asking
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function load() {
var data = [];
document.getElementById('btnSubmit').addEventListener('click', function () {
// var line = prompt("Enter course name, grade, and credit hours (e.g. CS320 B+ 4) ");
var name = document.getElementById("name").value
var score = document.getElementById("grade").value
var credit = document.getElementById("credit").value
var values = [name, score, credit];
data.push(values);
display(data);
reset();
});
}
function reset() {
document.getElementById("name").value = "";
document.getElementById("grade").value = "";
document.getElementById("credit").value = "";
}
function display(data) {
var points = {
"A": 4,
"B+": 3.5,
"B": 3,
"C+": 2.5,
"C": 2,
"D": 1,
"F": 0,
"AF": 0,
"WF": 0
};
var hours = 0;
var table = document.getElementById('result');
table.innerHTML = "
var sum = 0;
for (var i in data) {
var item = data[i];
table.innerHTML += "
item[0] + "
item[1] + "
sum += points[item[1]] * parseInt(item[2]);
hours += parseInt(item[2]);
}
var gpa = sum / hours;
var text = "
Total grade points = " + sum;
text += "
Number of hours = " + hours + "
";
text += "GPA = " + gpa; //printing the output
document.getElementById('text').innerHTML = text;
}
|
|
|
|
|
load();
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
my output looks like this
However it's wrong,
this is what it's asking for
this was my orignial code which i got full credit for,
function load() {
var data = [];
while (true) {
var line = prompt("Enter course name, grade, and credit hours (e.g. CS320 B+ 4) ");
if (line == null || line == "") {
break;
}
var values = line.split(/\s/);
data.push(values);
}
return data;
}
function display(data) {
var points = {
"A": 4,
"B+": 3.5,
"B": 3,
"C+": 2.5,
"C": 2,
"D": 1,
"F": 0,
"AF": 0,
"WF": 0
};
var hours = 0;
var table = document.getElementById('result');
table.innerHTML = "
var sum = 0;
for (var i in data) {
var item = data[i];
table.innerHTML += "
item[0] + "
item[1] + "
sum += points[item[1]] * parseInt(item[2]);
hours += parseInt(item[2]);
}
var gpa = sum / hours;
var text = "
Total grade points = " + sum;
text += "
Number of hours = " + hours + "
";
text += "GPA = " + gpa; //printing the output
document.getElementById('text').innerHTML = text;
}
data = load();
display(data);
Some help would be great, i can't seem to figure thsi out
Enter course name, grade, and credit hours (e.g. CS320 B+4) Course Name Grade credit Course Grade Hours CS32 KinlBA 3 1 Total grade points NaN Number of hours 3 GPA NaN OutputStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started