-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathT7.html
102 lines (96 loc) · 2.93 KB
/
T7.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
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
<html>
<head>
<style>
.container {
width: 500px;
margin: 0 auto;
text-align: center;
}
.form-group {
display: flex;
justify-content: center;
align-items: center;
margin: 20px 0;
}
label {
width: 150px;
text-align: right;
padding-right: 20px;
}
input[type="number"],
select {
width: 150px;
height: 32px;
padding: 6px 12px;
font-size: 14px;
line-height: 1.42857;
color: #555;
background-color: #fff;
background-image: none;
border: 1px solid #ccc;
border-radius: 4px;
}
button {
width: 150px;
height: 32px;
margin-top: 20px;
padding: 6px 12px;
font-size: 14px;
font-weight: 400;
line-height: 1.42857;
text-align: center;
white-space: nowrap;
vertical-align: middle;
touch-action: manipulation;
cursor: pointer;
user-select: none;
background-image: none;
border: 1px solid #ccc;
border-radius: 4px;
}
</style>
</head>
<body>
<div class="container">
<h1>Tip Calculator</h1>
<div class="form-group">
<label for="amount">Amount:</label>
<input type="number" id="amount" step="0.01" />
</div>
<div class="form-group">
<label for="tipPercentage">Tip Percentage:</label>
<select id="tipPercentage">
<option value="0.1">10%</option>
<option value="0.15">15%</option>
<option value="0.2">20%</option>
</select>
</div>
<div class="form-group">
<label for="people">Split among:</label>
<input type="number" id="people" value="1" />
</div>
<button id="calculateTip">Calculate</button>
<hr />
<h2>Tip per person: <span id="tip">$0.00</span></h2>
<h2>Total:<span id="total">Rs:0.00</span></h2>
</div>
<script>
const calculateTip = document.querySelector("#calculateTip");
const amountInput = document.querySelector("#amount");
const tipPercentageSelect = document.querySelector("#tipPercentage");
const peopleInput = document.querySelector("#people");
const tipSpan = document.querySelector("#tip");
const totalSpan = document.querySelector('#total');
calculateTip.addEventListener("click", function () {
const amount = parseFloat(amountInput.value);
const tipPercentage = parseFloat(tipPercentageSelect.value);
const people = parseInt(peopleInput.value);
tip = (amount * tipPercentage) / people;
tipSpan.innerHTML = tip;
total = amount + tip*people;
document.querySelector("#tip").innerHTML = tip;
totalSpan.innerHTML = total;
});
</script>
</body>
</html>