-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrateofchange.html
More file actions
28 lines (25 loc) · 856 Bytes
/
Copy pathrateofchange.html
File metadata and controls
28 lines (25 loc) · 856 Bytes
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
<!DOCTYPE HTML>
<html lang="en-us">
<head>
<meta charset="utf-8">
<title>Rate of Change</title>
<script>
function computeRateOfChange() {
//input and convert to integer
let previous = parseFloat(document.getElementById('prevPrice').value);
let current = parseFloat(document.getElementById('currPrice').value);
//math and rounding
rateOfChange = parseFloat((current - previous) / previous).toFixed(4);
//output
document.getElementById('rate').innerHTML = rateOfChange;
}
</script>
</head>
<body>
<h1>Rate of Change</h1>
Previous Price <input type="text" id="prevPrice"><br>
Current Price <input type="text" id="currPrice"><br>
<button type="button" onclick="computeRateOfChange()">Rate of Change</button><br>
Rate of Change <div id="rate"></div>
</body>
</html>