forked from tushargugnani/learningVueJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20.tip-calculator.html
66 lines (63 loc) · 2.92 KB
/
20.tip-calculator.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 lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<!-- development version, includes helpful console warnings -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body class="py-5">
<div id="app">
<div class="container">
<div class="row">
<div class="col-md-8 mx-auto">
<h2> Tip Calculator </h2>
<form>
<div class="form-group">
<label for="name">How much is the total Bill Amount?</label>
<input type="text" class="form-control" id="amount" placeholder="Total Bill Amount" v-model="amount">
</div>
<div class="form-group">
<label for="email">How was the service?</label>
<select name="refer" class="form-control" id="percentage" v-model="percentage">
<option value="30">30% (Exceptional)</option>
<option value="25">25% (More than good)</option>
<option value="20" selected>20% (Good)</option>
<option value="15">15% (It was okay)</option>
<option value="10">10% (Bad)</option>
<option value="5">5% (Terrible)</option>
</select>
</div>
<div class="form-group">
<label for="name">How many people are sharing the bill?</label>
<input type="number" class="form-control" id="people" placeholder="Number of people" v-model="people">
</div>
</form>
<div class="alert alert-success" role="alert">
Tip Amount : <strong>{{tip.toFixed(2)}} / person</strong>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
var app = new Vue({
el: '#app',
data: {
amount: 0,
percentage: 20,
people: 1
},
computed: {
tip(){
this.people = (!isNaN(this.people) && this.people > 0) ? this.people : 1; //Restrict people to not be NaN or 0
return this.amount > 0 ? (this.amount * this.percentage / 100) / this.people : 0; //Calculate Tip if valid bill amount
}
}
});
</script>
</body>
</html>