-
Notifications
You must be signed in to change notification settings - Fork 0
/
tip-widget.js
34 lines (33 loc) · 1.17 KB
/
tip-widget.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
async function tipImage() {
let tips = await fetch("./googleSheetUK.json");
tips = await tips.json();
let matchDate = new Date().toISOString().slice(5, 10);
let tipDate;
let dailyTip;
let dailyTipSource;
let tipAlt;
let tipTitle;
let tipSource;
for (let i = 0; i < tips.length; i += 1) {
if (tips[i].tipOfTheDayDate !== undefined) {
tipDate = (JSON.stringify(tips[i].tipOfTheDayDate)).substring(6, 11);
};
if ( tipDate === matchDate) {
dailyTip = tips[i].id
dailyTipSource = `./tip-images/${dailyTip}.png`;
tipAlt = tips[i].tip;
tipTitle = tips[i].graphicsTitle;
break;
};
}
if (dailyTipSource) {
tipSource = dailyTipSource;
} else {
tipSource = `./tip-images/generic_tip_image.jpg`;
tipAlt = "Select a category from the below options to see a tip.";
tipTitle = "Create your own Kindspace.";
}
document.getElementById('tip_image').src = tipSource;
document.getElementById('tip_image').alt = tipAlt;
document.getElementById('tip_image').title = tipTitle;
};