-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
137 lines (116 loc) · 6.05 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
let bill = document.getElementById("bill");
let numberOfPeople = document.getElementById("NOP");
let amount = document.getElementById("amount");
let total = document.getElementById("total");
////////////////
let ButtonFive = document.getElementById("5percent");
ButtonFive.addEventListener("click", calculateFive);
function calculateFive() {
let resultOne = bill.value * 5;
let resultTwo = resultOne / 100;
let resultThree = resultTwo / numberOfPeople.value;
let resultFour = bill.value / resultThree;
amount.innerHTML = resultThree;
total.innerHTML = resultFour;
document.getElementById("5percent").style.backgroundColor = "hsl(148, 36%, 40%)";
document.getElementById("10percent").style.backgroundColor = "hsl(183, 100%, 15%)";
document.getElementById("15percent").style.backgroundColor = "hsl(183, 100%, 15%)";
document.getElementById("25percent").style.backgroundColor = "hsl(183, 100%, 15%)";
document.getElementById("50percent").style.backgroundColor = "hsl(183, 100%, 15%)";
};
////////////////
let Buttonten = document.getElementById("10percent");
Buttonten.addEventListener("click", calculateTen);
function calculateTen() {
let resultOne = bill.value * 10;
let resultTwo = resultOne / 100;
let resultThree = resultTwo / numberOfPeople.value;
let resultFour = bill.value / resultThree;
amount.innerHTML = resultThree;
total.innerHTML = resultFour;
document.getElementById("10percent").style.backgroundColor = "hsl(148, 36%, 40%)";
document.getElementById("5percent").style.backgroundColor = "hsl(183, 100%, 15%)";
document.getElementById("15percent").style.backgroundColor = "hsl(183, 100%, 15%)";
document.getElementById("25percent").style.backgroundColor = "hsl(183, 100%, 15%)";
document.getElementById("50percent").style.backgroundColor = "hsl(183, 100%, 15%)";
};
////////////////
let ButtonFivteen = document.getElementById("15percent");
ButtonFivteen.addEventListener("click", calculateFivteen);
function calculateFivteen() {
let resultOne = bill.value * 15;
let resultTwo = resultOne / 100;
let resultThree = resultTwo / numberOfPeople.value;
let resultFour = bill.value / resultThree;
amount.innerHTML = resultThree;
total.innerHTML = resultFour;
document.getElementById("15percent").style.backgroundColor = "hsl(148, 36%, 40%)";
document.getElementById("5percent").style.backgroundColor = "hsl(183, 100%, 15%)";
document.getElementById("10percent").style.backgroundColor = "hsl(183, 100%, 15%)";
document.getElementById("25percent").style.backgroundColor = "hsl(183, 100%, 15%)";
document.getElementById("50percent").style.backgroundColor = "hsl(183, 100%, 15%)";
};
////////////////
let ButtonTwenyFive = document.getElementById("25percent");
ButtonTwenyFive.addEventListener("click", calculateTwenyFive);
function calculateTwenyFive() {
let resultOne = bill.value * 25;
let resultTwo = resultOne / 100;
let resultThree = resultTwo / numberOfPeople.value;
let resultFour = bill.value / resultThree;
amount.innerHTML = resultThree;
total.innerHTML = resultFour;
document.getElementById("25percent").style.backgroundColor = "hsl(148, 36%, 40%)";
document.getElementById("5percent").style.backgroundColor = "hsl(183, 100%, 15%)";
document.getElementById("10percent").style.backgroundColor = "hsl(183, 100%, 15%)";
document.getElementById("15percent").style.backgroundColor = "hsl(183, 100%, 15%)";
document.getElementById("50percent").style.backgroundColor = "hsl(183, 100%, 15%)";
};
////////////////
let ButtonFifty = document.getElementById("50percent");
ButtonFifty.addEventListener("click", calculateFifty);
function calculateFifty() {
let resultOne = bill.value * 50;
let resultTwo = resultOne / 100;
let resultThree = resultTwo / numberOfPeople.value;
let resultFour = bill.value / resultThree;
amount.innerHTML = resultThree;
total.innerHTML = resultFour;
document.getElementById("50percent").style.backgroundColor = "hsl(148, 36%, 40%)";
document.getElementById("5percent").style.backgroundColor = "hsl(183, 100%, 15%)";
document.getElementById("10percent").style.backgroundColor = "hsl(183, 100%, 15%)";
document.getElementById("15percent").style.backgroundColor = "hsl(183, 100%, 15%)";
document.getElementById("25percent").style.backgroundColor = "hsl(183, 100%, 15%)";
};
////////////////
let ButtonCustome = document.getElementById("custome-input");
ButtonCustome.addEventListener("focusout", calculateCustome);
function calculateCustome() {
let resultOne = bill.value * ButtonCustome.value;
let resultTwo = resultOne / 100;
let resultThree = resultTwo / numberOfPeople.value;
let resultFour = bill.value / resultThree;
amount.innerHTML = resultThree;
total.innerHTML = resultFour;
document.getElementById("5percent").style.backgroundColor = "hsl(183, 100%, 15%)";
document.getElementById("10percent").style.backgroundColor = "hsl(183, 100%, 15%)";
document.getElementById("15percent").style.backgroundColor = "hsl(183, 100%, 15%)";
document.getElementById("25percent").style.backgroundColor = "hsl(183, 100%, 15%)";
document.getElementById("50percent").style.backgroundColor = "hsl(183, 100%, 15%)";
};
////////////////
let resetButton = document.getElementById("reset-btn");
resetButton.addEventListener("click", reset);
function reset() {
amount.innerHTML = "$0.00"
total.innerHTML = "$0.00"
ButtonCustome.value = "custome"
numberOfPeople.value = "0"
bill.value = "0"
document.getElementById("5percent").style.backgroundColor = "hsl(183, 100%, 15%)";
document.getElementById("10percent").style.backgroundColor = "hsl(183, 100%, 15%)";
document.getElementById("15percent").style.backgroundColor = "hsl(183, 100%, 15%)";
document.getElementById("25percent").style.backgroundColor = "hsl(183, 100%, 15%)";
document.getElementById("50percent").style.backgroundColor = "hsl(183, 100%, 15%)";
}
console.log("Challenge by Frontend Mentor - https://www.frontendmentor.io?ref=challenge. Coded by Hossein rahmati - https://github.com/hosseinrmt.");