-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
25 lines (22 loc) · 816 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
const quoteText = document.querySelector(".quote"),
authorName = document.querySelector(".author .name"),
quoteBtn = document.querySelector("button"),
copyBtn = document.querySelector(".copy");
// random quote function
function randomQuote(){
quoteBtn.classList.add("loading");
quoteBtn.innerText = "Loading..."
// fetching random quote/data dari API
fetch("https://api.quotable.io/random").then(res => res.json()).then(result =>{
console.log(result);
quoteText.innerText = result.content;
authorName.innerText = result.author;
quoteBtn.innerText = "New Quote";
quoteBtn.classList.remove("loading");
});
}
// copy text quote
copyBtn.addEventListener("click", ()=>{
navigator.clipboard.writeText(quoteText.innerText);
});
quoteBtn.addEventListener("click", randomQuote);