Question
JavaScript: I cant get my code to display the Letter grade for the following assignment. The code is included below. My assignment is to convert
JavaScript:
I cant get my code to display the Letter grade for the following assignment. The code is included below.
My assignment is to convert number grades to letter grades. It is supposed to provide practice using if statements. To start the application should display a prompt dialog box that gets numbers from 0 to 100. Then it should display an alert dialog box that displays the number grade (Number grade = 95) a new line, and the letter grade (Letter grade = A). Add the JavaScript code for deriving the letter grade and displaying it in in an alert dialog box. Data validation for numbers 0 to 100 and display the starting prompt dialog box, no need for a special error message.
var entry;
var scores = [];
var total = 0;
var show = "The test scores: ";
var grade;
var letterGrades = [];
var more = "The letter grades: ";
// use a do-while loop to get scores from user
do {
entry = prompt("Enter test score " +
"Or enter 999 to end entries", 999);
entry = parseInt(entry);
if (entry >= 0 && entry <= 100) {
scores[scores.length] = entry;
} else if (entry != 999){
alert("Entry must by a valid number from 0 through 100 " +
"Or enter 999 to end entries");
}
if (entry > 87 && entry <= 100) {
grade = "A";
}
else if (entry > 79 && entry <= 87) {
grade = "B";
}
else if (entry > 67 && entry <= 79) {
grade = "C";
}
else if (entry > 59 && entry <= 67) {
grade = "D";
}
else if (entry >= 0 && entry <= 60) {
grade = "F";
}
}
while (entry != 999);
if (scores.length != 0) {
// use a for loop to process the scores
for (var i = 0; i < scores.length; i++) {
show = show + scores[i] + " ";
}
alert(show);
}
if (letterGrades.length != 0){
letterGrades[letterGrades.length] = grade;
for (var i = 0; i < letterGrades.length; i++) {
more = more + letterGrades[j] + " ";
}
alert(more);
}
This page is displayed after the JavaScript is executed
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