-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.js
35 lines (26 loc) · 1.09 KB
/
main.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
const Wish = document.getElementById('demo');
const btn = document.getElementById('btn');
const twt = document.getElementById('twt');
const fb = document.getElementById('fb');
const mail = document.getElementById('mail');
const whatsapp = document.getElementById('whatsapp');
btn.addEventListener('click', getWish);
getWish();
function getWish() {
fetch("https://iamsonukushwaha.github.io/diwali-wishes/db.json")
.then(function (response) {
return response.json();
})
.then(function (data) {
// console.log(data);
let index = Math.floor(Math.random() * data.length);
// console.log(index);
var wish = data[index].wish;
Wish.textContent = wish;
// links
twt.href = `https://twitter.com/intent/tweet?text=${wish}`;
fb.href = `https://facebook.com/sharer/sharer.php?u=https://singlebucks.blogspot.com/diwali-wishes/`;
mail.href = `mailto:?subject=Happy%20Diwali&body=${wish}`;
whatsapp.href = `https://api.whatsapp.com/send/?text=${wish}`;
});
}