-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
27 lines (26 loc) · 887 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
const getTime = () => {
const date = new Date();
const hours = String(date.getHours()).padStart(2, "0");
const minutes = String(date.getMinutes()).padStart(2, "0");
return `${hours}:${minutes}`;
};
const interval = setInterval(() => {
document.getElementById("time").innerHTML = getTime();
}, 1000);
const api_url = "https://api.quotable.io/quotes/random";
const quote = document.getElementById("quote");
const author = document.getElementById("author");
async function getapi(url) {
await fetch(url)
.then((response) => response.json())
.then((data) => {
quote.innerHTML = `<q><i>${data[0].content}</i></q>`;
author.innerHTML = data[0].author;
})
.catch((err) => {
console.log(err);
quote.innerHTML = `<q><i>Never stop to say Do it now!</i></q>`;
author.innerHTML = "Anonymous";
});
}
getapi(api_url);