Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alaminfirdows/08a1eac8ccf2a454ec8b64550101f1be to your computer and use it in GitHub Desktop.
Save alaminfirdows/08a1eac8ccf2a454ec8b64550101f1be to your computer and use it in GitHub Desktop.
Show discount by country
<!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