-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
103 lines (88 loc) · 3.2 KB
/
Copy pathindex.html
File metadata and controls
103 lines (88 loc) · 3.2 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
background-color: #1d1d1d;
color: white;
}
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 95vh;
}
input {
margin: 10px;
padding: 10px 20px;
border: 1px solid #ccc;
border-radius: 8px;
background-color: #1a1a1a;
color: white;
}
button {
margin: 10px;
padding: 10px 20px;
border: 1px dashed #000;
border-radius: 8px;
background-color: #ccc;
cursor: pointer;
}
button:hover {
background-color: #000;
color: #fff;
}
code {
font-size: large;
margin-top: 20px;
color: white;
}
</style>
<title>Stonks 🚀</title>
</head>
<body>
<div class="container">
<h1>Where's my Stonks?</h1>
<input type="number" placeholder="Stock Price" id="initial-price">
<input type="number" placeholder="Quantity" id="quantity">
<input type="number" placeholder="Current Price" id="current-price">
<button id="calculate-btn">Calculate</button>
<code id="output"></code>
</div>
<script>
const calculateBtn = document.querySelector("#calculate-btn");
const output = document.querySelector("#output");
calculateBtn.addEventListener("click", () => {
const initialPrice = document.querySelector("#initial-price").value;
const quantity = document.querySelector("#quantity").value;
const currentPrice = document.querySelector("#current-price").value;
if (initialPrice && quantity && currentPrice) {
calculateProfitAndLoss(initialPrice, quantity, currentPrice);
} else {
output.innerText = "Please enter all the fields";
}
});
function calculateProfitAndLoss(initial, qty, current) {
if (initial > current) {
const loss = (initial - current) * qty;
const lossPercentage = (loss / initial) * 100;
showOutput(`Hey the loss is ${loss} and the loss percentage is ${Math.trunc(lossPercentage)}%`);
} else if (current > initial) {
const profit = (current - initial) * qty;
const profitPercentage = (profit / initial) * 100;
showOutput(`Hey the profit is ${profit} and the percent is ${Math.trunc(profitPercentage)}%`);
} else {
showOutput("No pain no gain and no gain no pain :)");
}
}
function showOutput(message) {
output.innerText = message;
}
</script>
</body>
</html>