Created
August 25, 2020 06:24
-
-
Save alaminfirdows/08a1eac8ccf2a454ec8b64550101f1be to your computer and use it in GitHub Desktop.
Show discount by country
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Document</title> | |
<style> | |
#discount-bar { | |
background: #ff003bbf; | |
padding: 10px; | |
color: #fff; | |
margin: 0; | |
text-align: center; | |
font-family: sans-serif; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="discount-bar"></div> | |
<script> | |
let discounts = [{ | |
id: 1, | |
timezone: 'Asia/Dhaka', | |
country: 'Bangladesh', | |
discount: '90%', | |
}, { | |
id: 1, | |
timezone: 'Asia/Tokyo', | |
country: 'Japan', | |
discount: '70%', | |
}]; | |
let timezone = Intl.DateTimeFormat().resolvedOptions().timeZone; | |
let myDiscount = discounts.find((discount) => { | |
return timezone == discount.timezone | |
}) | |
switch (myDiscount.timezone) { | |
case 'Asia/Dhaka': | |
discountText = `It looks like you from Banglades! Use "TX_JOSS" to get ${myDiscount.discount} discount.`; | |
break; | |
default: | |
discountText = `Boom! You have no discount`; | |
break; | |
} | |
document.getElementById('discount-bar').innerHTML = discountText; | |
console.log(discountText) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment