ASDV-WebDev/Semester 1/Chapter ZIPs/JavaScript/ch8/ex_8_8.html

34 lines
861 B
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Example 8.8</title>
<script type="text/javascript">
var names = new Array();
var grades = new Array();
var high = 0;
var index = 0;
var k = 0;
while (names[k] != "*")
{
names[k]= prompt("Enter the student's name or enter an asterisk (*) when you are done: ");
if (names[k] == "*")
{
break;
}
grades[k]= prompt("Enter the student's grade: ");
grades[k] = parseFloat(grades[k]);
document.write("Name of student " + (k + 1) + ": " + names[k] + " grade: " + grades[k] + "<br />");
if (grades[k] > high)
{
index = k;
high = grades[index];
}
k = k + 1;
}
document.write("The highest grade in the class is: " + grades[index] + "<br />");
document.write(names[index] + " is the high-achieving student! <br />");
</script>
</head>
<body>
</body></html>