-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpart1_3.html
More file actions
79 lines (66 loc) · 3.15 KB
/
Copy pathpart1_3.html
File metadata and controls
79 lines (66 loc) · 3.15 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
<!DOCTYPE html>
<html>
<head>
<title>Part 1: Student Grades</title>
</head>
<body>
<h1>Student Grades</h1>
<!-- Form for entering student grades -->
<form id="gradeForm">
<label for="hwAvg">Homework Average:</label>
<input type="number" id="hwAvg" name="hwAvg" min="0" max="100" required><br>
<label for="midExam">Mid-Term Exam Score:</label>
<input type="number" id="midExam" name="midExam" min="0" max="100" required><br>
<label for="finalExam">Final Exam Score:</label>
<input type="number" id="finalExam" name="finalExam" min="0" max="100" required><br>
<label for="participation">Participation:</label>
<input type="number" id="participation" name="participation" min="0" max="100" required><br>
<button type="button" id="calculateButton">Calculate</button>
<button type="button" id="clearButton">Clear</button>
</form>
<!-- Output area for results and error message -->
<div id="output"></div>
<script>
document.getElementById("calculateButton").addEventListener("click", function() {
// Get input values
const hwAvg = parseFloat(document.getElementById("hwAvg").value);
const midExam = parseFloat(document.getElementById("midExam").value);
const finalExam = parseFloat(document.getElementById("finalExam").value);
const participation = parseFloat(document.getElementById("participation").value);
// Check for valid input
if (isNaN(hwAvg) || isNaN(midExam) || isNaN(finalExam) || isNaN(participation)) {
document.getElementById("output").textContent = "Invalid input. Please enter valid grades.";
return;
}
// Calculate final average
const finalAverage = (.5 * hwAvg) + (.2 * midExam) + (.2 * finalExam) + (.1 * participation);
// Calculate letter grade
let 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
document.getElementById("output").textContent = `Final Average: ${Math.round(finalAverage)} (${letterGrade})`;
// Check if the student must retake the course
if (letterGrade === "D" || letterGrade === "F") {
document.getElementById("output").textContent += "\nStudent must retake the course.";
}
});
document.getElementById("clearButton").addEventListener("click", function() {
// Clear the form and output area
document.getElementById("gradeForm").reset();
document.getElementById("output").textContent = "";
});
<!-- Create a button that links back to Homework3.html -->
<button onclick="window.location.href='homework3.html'">Go Back to Homework 3</button>
</script>
</body>
</html>