-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscount.js
42 lines (38 loc) · 1.3 KB
/
discount.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
// 8(Discount)
/*
1. if ticket numbers is less than 100, per ticket price: 100
2. if ticket numbers is more than 100, but less than 200. First 100 tickets will be 100/ticket.
rest tickets will be 90 taka per piece
first 100 ---->100tk
rest ----> 90tk
3. if you purchase more than 200 tickets
first 100 ---> 100tk
101-200 ---> 90tk
200+ ----> 70tk
*/
function ticketPrice(ticketQuantity){
const first100Rate = 100;
const second100Rate = 90;
const restTicketRate = 70;
if(ticketQuantity <= 100 ){
const price = ticketQuantity * first100Rate;
return price;
}
else if(ticketQuantity <= 200){
const first100Price = 100 * first100Rate;
const restTicketQuantity = ticketQuantity - 100;
const restTicketPrice = restTicketQuantity * second100Rate;
const totalPrice = first100Price + restTicketPrice;
return totalPrice;
}
else{
const first100Price = 100 * first100Rate;
const second100Price = 100 * second100Rate;
const restTicketQuantity = ticketQuantity - 200;
const restTicketPrice = restTicketQuantity * restTicketRate;
const totalCost = first100Price + second100Price + restTicketPrice;
return totalCost;
}
}
const price = ticketPrice(120);
console.log('price: ', price);