Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // kalau tanggalnya itu cocok berarti discount berakhir
- // kalau tanggalnya tidak cocok discount belum berakhir
- function discountProduct(date, discountPrice, salePrice) {
- let intMonth = 0
- const d= new Date()
- const month = ['January','February','March','April','May','June','July','August','September','October', 'November','December'];
- const dateMonth = [31,29,31,30,31,30,31,31,30,31,30,31]
- const dateNow = d.getDate()
- const monthIndex = month.indexOf(month[date.getMonth()])
- const dateMonthIndex = dateMonth[monthIndex]
- const discountDate = new Date(date)
- for(let i = 0; i < dateMonthIndex; i++) {
- if(dateNow === i) {
- intMonth += i
- }
- }
- const discountDateOver = discountDate.getDate() !== intMonth ? discountPrice : salePrice
- return discountDateOver
- }
- const resultDiscountPrice = discountProduct('2020-11-17', true, false)
- console.log(resultDiscount);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement