-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpart1page.html
More file actions
80 lines (65 loc) · 2.98 KB
/
Copy pathpart1page.html
File metadata and controls
80 lines (65 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!DOCTYPE html>
<html>
<head>
<title>Grade Calculator</title>
</head>
<body>
<h1>Part 1: Student Grades</h1>
<h2>Grade Calculator</h2>
<form id="gradeForm">
<label for="hwAvg">Homework Average:</label>
<input type="number" id="hwAvg" name="hwAvg" min="0" max="100" required><br><br>
<label for="midExam">Mid-Term Exam Score:</label>
<input type="number" id="midExam" name="midExam" min="0" max="100" required><br><br>
<label for="finalExam">Final Exam Score:</label>
<input type="number" id="finalExam" name="finalExam" min="0" max="100" required><br><br>
<label for="participation">Participation:</label>
<input type="number" id="participation" name="participation" min="0" max="100" required><br><br>
<input type="button" value="Calculate" onclick="calculateGrade()">
<input type="button" value="Clear Form" onclick="clearForm()">
</form>
<div id="result"></div>
<script>
function calculateGrade() {
// Get input values
var hwAvg = parseFloat(document.getElementById("hwAvg").value);
var midExam = parseFloat(document.getElementById("midExam").value);
var finalExam = parseFloat(document.getElementById("finalExam").value);
var participation = parseFloat(document.getElementById("participation").value);
// Check for valid input
if (isNaN(hwAvg) || isNaN(midExam) || isNaN(finalExam) || isNaN(participation) ||
hwAvg < 0 || hwAvg > 100 || midExam < 0 || midExam > 100 || finalExam < 0 || finalExam > 100 || participation < 0 || participation > 100) {
document.getElementById("result").innerHTML = "Invalid input. Please enter valid grades (0-100).";
return;
}
// Calculate final average
var finalAverage = (.5 * hwAvg) + (.2 * midExam) + (.2 * finalExam) + (.1 * participation);
// Determine letter grade
var letterGrade = "";
if (finalAverage >= 90) {
letterGrade = "A";
} else if (finalAverage >= 80) {
letterGrade = "B";
} else if (finalAverage >= 70) {
letterGrade = "C";
} else if (finalAverage >= 60) {
letterGrade = "D";
} else {
letterGrade = "F";
}
// Display result
var resultMessage = "Final Average: " + Math.round(finalAverage) + "<br>Letter Grade: " + letterGrade;
if (letterGrade == "D" || letterGrade == "F") {
resultMessage += "<br>Student must retake the course";
}
document.getElementById("result").innerHTML = resultMessage;
}
function clearForm() {
document.getElementById("gradeForm").reset();
document.getElementById("result").innerHTML = "";
}
</script>
<a href="homework3.html">Return to Homework 3</a>
</body>
</html>
```