-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
48 lines (42 loc) · 964 Bytes
/
script.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
36
37
38
39
40
41
42
43
44
45
46
47
const greeting = document.getElementById('greeting');
const generate = document.getElementById('generate');
const activity = document.getElementById('activity');
const date = new Date();
let day;
switch (date.getDay()) {
case 0:
day = 'Sunday';
break;
case 1:
day = 'Monday';
break;
case 2:
day = 'Tuesday';
break;
case 4:
day = 'Wednesday';
break;
case 5:
day = 'Thursday';
break;
case 6:
day = 'Friday';
break;
case 7:
day = 'Saturday';
break;
}
greeting.innerHTML = `Happy ${day}!`;
async function getActivity() {
const api = 'http://www.boredapi.com/api/activity/';
try {
let response = await fetch(api);
let data = await response.json();
activity.innerHTML = data.activity;
} catch (err) {
console.log(err);
activity.innerHTML = 'Let\'s start coding';
}
generate.innerHTML = 'Pick another activity';
}
generate.addEventListener('click', getActivity);