Question
I really need help for this Write a Javascript program (i.e. script) that inputs a sequence of names and grades, computes the average of the
I really need help for this
Write a Javascript program (i.e. script) that inputs a sequence of names and grades, computes the average of the grades, and displays the names, grades, and average in an HTML page. Since Javascript doesnt have input/output statements in the normal programming sense it operates as a script in an HTML document, you will need to figure out a way to input the sequence of names and grades. [I use the prompt function to do this.] Similarly, for output you will need to modify the HTML document to output the answer. This can be as simple as replacing the document with the answer using document.write().
(Note: All output should be in a table except the average grade. Please include the letter grade too.)
Letter Grade Description
A
90 and above
B
80 89
C
70 79
D
60 69
F
Below 60
(Please use this code)
// Filename gradingpapers.html
// Program loops until the teacher does not have any
// additional students
var names = new Array();
var grades = new Array();
var ans = 'Y';
i = 0;
total = 0;
while (ans == 'Y') {
names[i] = prompt("Enter student name:");
grades[i] = prompt("What was their test grade?");
total += parseFloat(grades[i]);
ans = prompt("Do you have another grade? (Y/N)");
++i;
}
for (j = 0; j < i; ++j) {
document.write(names[j] + " got a " + grades[j] + "! ");
}
average = total / j;
document.write("
The class average was " + average);
Step 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