-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
74 lines (62 loc) · 2.7 KB
/
Copy pathscript.js
File metadata and controls
74 lines (62 loc) · 2.7 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
var bill, billValue = 0, peopleNum = 1, people, tipAmountpp, tipPercent, tipPercentValue = 0;
var totalAmountpp;
var btn = document.getElementById("reset");
function getBillValue(){
bill = document.getElementById("bill").value;
billValue = parseFloat(bill);
console.log(billValue);
}
$('.tip-percentage').click(function(e) {
$('.tip-percentage').removeClass('active');
$(this).addClass('active');
});
function getTipPercent(){
tipPercentValue = parseFloat(tipPercent);
console.log(tipPercentValue);
}
function custom(){
document.getElementById("custom").type = "number";
document.getElementById("custom").style = "text-align: right; outline: none;color: hsl(186, 14%, 43%);background-color: hsl(185, 61%, 92%);";
}
function getCustom(){
tipPercent = document.getElementById("custom").value;
tipPercentValue = parseInt(tipPercent);
console.log(tipPercentValue);
}
function getPeopleNum(){
people = document.getElementById("people-num").value;
if(parseInt(people) == 0 ){
document.getElementById("people-num").setCustomValidity("Number of people can't be 0.");
document.getElementById("people-error").innerHTML = "can't be zero";
document.getElementById("people-num").style = "border: solid 1px red;";
}
else if(parseInt(people) < 0 || !Number.isInteger(parseFloat(people) )){
document.getElementById("people-num").setCustomValidity("It's not possible");
document.getElementById("people-error").innerHTML = "It's not possible";
document.getElementById("people-num").style = "border: solid 1px red;";
}
else{
document.getElementById("people-error").innerHTML = "";
peopleNum = parseInt(people);
console.log(peopleNum);
}
}
tipAmountpp = document.getElementById("tip-value");
totalAmountpp = document.getElementById("total-value");
function tipUpdate(){
tipAmountpp.innerHTML = "$" + ((billValue * tipPercentValue /100)/peopleNum).toFixed(2) ;
totalAmountpp.innerHTML = "$" + (((billValue * tipPercentValue /100) + billValue)/peopleNum).toFixed(2);
console.log("tipupdate");
}
function reset(){
$('.tip-percentage').removeClass('active');
btn.style = "background-color: hsl(172, 67%, 45%);";
document.getElementById("people-num").value = 0;
document.getElementById("bill").value = 0;
document.getElementById("bill").style = "border: none;";
document.getElementById("custom").type = "button";
document.getElementById("custom").value = "custom";
document.getElementById("custom").style = "border: none; outline: none;color: hsl(186, 14%, 43%);background-color: hsl(185, 61%, 92%);";
tipAmountpp.innerHTML = "$0.00";
totalAmountpp.innerHTML = "$0.00";
}