-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
66 lines (57 loc) · 1.49 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<title>Cost Calculator</title>
<meta name="description" content="Calculates total cost based on marginal rates">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 8px;
}
</style>
</head>
<body id='body'>
<h1>Cost Calculator</h1>
<p>Calculates the total cost based on the following <b>marginal rates</b>
<br>
<table>
<tr><th>Rate</th><th>Units</th></tr>
<tr><td>$90</td><td>1-5</td></tr>
<tr><td>$85</td><td>6-10</td></tr>
<tr><td>$80</td><td>11-15</td></tr>
<tr><td>$75</td><td>16+</td></tr>
</table>
<br>
<input type="text" id="input" value="" onkeyup="textEnter(event)">
<input type="button" value="Submit" onclick="receiveSubmission()">
</p>
<p id="response"></p>
<script>
function receiveSubmission() {
x = document.getElementById("input").value
result = 0
if (x <= 0) {
document.getElementById("response").textContent = "Put in a positive integer"
return
}
if (x <= 5)
result = 90 * x
else if (x <= 10)
result = 85 * (x - 5) + 450
else if (x <= 15)
result = 80 * (x - 10) + 875
else
result = 75 * (x - 15) + 1275
document.getElementById("response").textContent = result
}
function textEnter(event) {
if (event.keyCode == 13)
receiveSubmission()
}
</script>
</body>
</html>