Skip to content

Commit 9224b0a

Browse files
committed
tip-calculator finished
1 parent bd088f7 commit 9224b0a

File tree

3 files changed

+84
-2
lines changed

3 files changed

+84
-2
lines changed

tip-calculator/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ <h1 class="title">Tip Calculator</h1>
1414
<label for="amount">Bill amount:
1515
<input type="number" id="amount">
1616
</label>
17-
<label for="percentae">
17+
<label for="percentage"> Tip percentage:
1818
<input type="number" name="" id="percentage">
1919
</label>
2020

2121
<button id="calculate">Calculate</button>
22-
<h2 id="total">Total: <span id="totalValue"></span></h2>
22+
<h3 id="total">Total: <span id="totalValue">0</span></h3>
2323
</div>
2424
</main>
2525
<script src="script.js"></script>

tip-calculator/script.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const amount = document.getElementById("amount");
2+
const percentage = document.getElementById("percentage");
3+
const totalValue = document.getElementById("totalValue");
4+
const calculate = document.getElementById("calculate");
5+
6+
const total = () => {
7+
const billValue = amount.value;
8+
const tipValue = percentage.value;
9+
const finalAmount = billValue * (1 + tipValue/100);
10+
totalValue.innerText = finalAmount.toFixed(2);
11+
};
12+
13+
calculate.addEventListener("click", total);
14+
percentage.addEventListener("keydown", (e) => {
15+
if (e.key === 'Enter'){
16+
total();
17+
}
18+
})

tip-calculator/styles.css

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,68 @@
11
* {
22
margin: 0;
33
padding: 0;
4+
}
5+
6+
body {
7+
background-color: #f2f2f2;
8+
font-family: "Helvetica", sans-serif;
9+
}
10+
11+
main {
12+
margin-top: 100px;
13+
display: flex;
14+
justify-content: center;
15+
}
16+
17+
.container {
18+
min-width: 40%;
19+
max-width: 600px;
20+
background-color: #ffffff;
21+
display: flex;
22+
flex-direction: column;
23+
padding: 20px;
24+
border-radius: 10px;
25+
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2);
26+
27+
}
28+
29+
button {
30+
background-color: #4caf50;
31+
color: #ffffff;
32+
padding: 0.8rem 0;
33+
border: none;
34+
cursor: pointer;
35+
font-size: 1.5rem;
36+
text-transform: uppercase;
37+
}
38+
39+
button:hover {
40+
background-color: gray;
41+
color: #000;
42+
}
43+
h1 {
44+
text-align: center;
45+
padding: 1rem 0;
46+
}
47+
48+
p {
49+
padding: 1rem 0 ;
50+
51+
}
52+
53+
label {
54+
padding: 1rem 0 ;
55+
display: block;
56+
}
57+
58+
input {
59+
margin-top: 0.5rem;
60+
height: 1.5rem;
61+
width: 100%;
62+
display: block;
63+
}
64+
65+
h3 {
66+
padding: 1rem 0;
67+
margin-top: 10px;
468
}

0 commit comments

Comments
 (0)