-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhw3part1.html
More file actions
131 lines (112 loc) · 5.04 KB
/
hw3part1.html
File metadata and controls
131 lines (112 loc) · 5.04 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<!DOCTYPE html>
<html lang="en">
<head>
<!--Kristian Reyes 9/12/2020 -->
<title>CNIT 133 Homework 3</title>
<meta charset="utf-8">
<meta name="description" content="homework 3 for CCSF CNIT 133">
<meta name="keywords" content="HTML, CSS, Javascript, CCSF, Student">
<meta name="author" content="Kristian Reyes">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--bootstrap -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"
></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<!--bootstrap -->
<script>
function finalGrade()
{
event.preventDefault();
document.getElementById("inputErr").innerHTML = "";
var hwAvg, midExam, finalExam, participation, finalAverage;
hwAvg = document.getElementById("hwAvg").value;
midExam = document.getElementById("midExam").value;
finalExam = document.getElementById("finalExam").value;
participation = document.getElementById("participation").value;
var errMsg = "<span style='font-weight: bold; color: red; font-size: 20px;'> Input is invalid. Only enter positive integers between 0 and 100. </span>";
if (isNaN(hwAvg) || isNaN(midExam) || isNaN(finalExam) || isNaN(participation) || hwAvg < 0 || midExam < 0 || finalExam < 0 || participation < 0 || hwAvg > 100|| midExam > 100 || finalExam > 100 || participation > 100)
document.getElementById("inputErr").innerHTML = errMsg;
else
{
finalAverage = (.5 * hwAvg) + (.2 * midExam) + (.2 * finalExam) + (.1 * participation);
switch (true)
{
// Display the final grade based on final average
case (finalAverage >= 90):
document.getElementById("final").innerHTML = (finalAverage + ". " + "The student has a grade of A.");
break;
case (finalAverage >= 80):
document.getElementById("final").innerHTML = (finalAverage + ". " + "The student has a grade of B.");
break;
case (finalAverage >= 70):
document.getElementById("final").innerHTML = (finalAverage + ". " + "The student has a grade of C.");
break;
case (finalAverage >= 60):
document.getElementById("final").innerHTML = (finalAverage + ". " + "The student has a grade of D.");
break;
case (finalAverage <= 59):
document.getElementById("final").innerHTML = (finalAverage + ". " + "The student has a grade of F. Student must retake the course.");
break;
}
}}
</script>
<body>
<main class="grid">
<header class="grid-area grid-area-1">
<h2> Homework 3 - Part 1 </h2>
</header>
<nav class="grid-area grid-area-2">
<ul>
<li>
<a href="homework3.html" title="CNIT 133 - HW 3">
Return to CNIT 133 Homework 3 - Functions
</a>
</li>
</ul>
</nav>
<section class="grid-area grid-area-3">
<h1> HW 3 - Part 1 </h1>
<h2> Student Grades </h2>
<p> Please enter student scores below.</p>
<form name="myform">
<table>
<tr>
<td>Homework Average Score:</td>
<td><input id="hwAvg" type="number" ></td>
</tr>
<tr>
<td>Mid-term Exam Score:</td>
<td><input id="midExam" type="number" ></td>
</tr>
<tr>
<td>Final Exam Score:</td>
<td><input id="finalExam" type="number" ></td>
</tr>
<tr>
<td>Participation Score:</td>
<td><input id="participation" type="number" ></td>
</tr>
</table>
</form>
<br>
<div id ="inputErr"></div>
<br>
<br>
<p> Submit results to calculate student's final average.</p>
<button onclick="finalGrade()">Submit</button>
<br>
<p> The student's final average is: </p>
<p>
<input type="text" id="final" size="60">
</p>
</section>
<footer class="grid-area grid-area-4">
<p>
© 2020 Kristian Reyes
</p>
</footer>
</main>
</body>
</html>