-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
31 lines (24 loc) · 942 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
const API_URL = "https://api.quotable.io/random";
const quoteText = document.getElementById("text");
const quoteAuthor = document.getElementById("author");
const newQuoteBtn = document.getElementById("new-quote");
const tweetQuoteBtn = document.getElementById("tweet-quote");
function getRandomQuote() {
return axios.get(API_URL).then((res) => res.data);
}
function setQuote(quote) {
quoteText.textContent = `"${quote.content}"`;
quoteAuthor.textContent = `- ${quote.author}`;
}
function setRandomQuote() {
getRandomQuote().then((quote) => setQuote(quote));
}
function tweetQuote() {
const quote = quoteText.textContent.trim();
const author = quoteAuthor.textContent.trim();
const twitterUrl = `https://twitter.com/intent/tweet?text=${quote} - ${author}`;
window.open(twitterUrl, "_blank");
}
newQuoteBtn.addEventListener("click", setRandomQuote);
tweetQuoteBtn.addEventListener("click", tweetQuote);
setRandomQuote();