-
Notifications
You must be signed in to change notification settings - Fork 0
/
Script.js
89 lines (68 loc) · 2.59 KB
/
Script.js
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
var button = document.querySelectorAll(".btn")
button.forEach((btn)=>{
btn.addEventListener("click", (e)=>{
const number = e.currentTarget.innerHTML
const realNumber = number.slice(0,2)
const alsoRealNumber = parseInt(realNumber)
const bill = document.getElementById("bill").value
const people = document.getElementById("people").value
const showAmount = document.getElementById("tipAmt")
const showTotal = document.getElementById("totPsn")
let tip = ( (alsoRealNumber / 100) * bill) / people
let total = ( (tip * people) + bill ) / people
if (bill.length == 0 || people.length == 0) {
return
}
// if (total == NaN) {
// showTotal.innerHTML = `$0.00`
// return false
// }
showAmount.innerHTML = `$${tip.toFixed(2)}`
showTotal.innerHTML = `$${total.toFixed(2)}`
})
})
function showTip(){
const custom = document.getElementById("custom").value
const bill = document.getElementById("bill").value
const people = document.getElementById("people").value
const showAmount = document.getElementById("tipAmt")
const showTotal = document.getElementById("totPsn")
let tip = ( (custom / 100) * bill) / people
let total = ( (tip * people) + bill ) / people
if (bill.length == 0 || people.length == 0 || custom.length == 0) {
return
}
// if (total == NaN) {
// showTotal.innerHTML = `$0.00`
// }
showAmount.innerHTML = `$${tip.toFixed(2)}`
showTotal.innerHTML = `$${total.toFixed(2)}`
}
function validateInputMoney(){
let bill = document.getElementById("bill").value
if (bill.length == 0) {
document.getElementById("rf1").innerHTML = "Can't be blank"
document.getElementById("rf1").style.display = "block"
document.getElementById("bill").style.borderColor = "red"
return false
}
document.getElementById("rf1").style.display = "none"
document.getElementById("bill").style.borderColor = "hsl(172, 67%, 45%)"
return true
}
function validateInputPeople(){
let people = document.getElementById("people").value
if (people.length == 0) {
document.getElementById("rf2").innerHTML = "Can't be blank"
document.getElementById("rf2").style.display = "block"
document.getElementById("people").style.borderColor = "red"
return false
}
document.getElementById("rf2").style.display = "none"
document.getElementById("people").style.borderColor = "hsl(172, 67%, 45%)"
return true
}
function resetFunction(){
document.getElementById('frm1').reset()
document.getElementById('frm2').reset()
}