-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (30 loc) · 982 Bytes
/
index.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
const quotes = document.querySelector('#quote');
const author = document.querySelector('#author');
const newQuote = document.querySelector("#newQuote");
const tweetMe = document.querySelector('#tweetMe')
let realData="";
let quotesData="";
const tweetNow = ()=>{
let tweetPost = `https://twitter.com/intent/tweet?text=${quotesData.text}${quotesData.author}`;
window.open(tweetPost);
}
const getNewQuotes = () => {
const rnum = Math.floor(Math.random() * 20);
quotesData = realData[rnum]
quotes.innerHTML = `${quotesData.text}`;
quotesData.author === null
? (author.innerHTML = 'Unknown')
: (author.innerHTML = `--${quotesData.author}`);
};
const getQuotes = async () => {
try{
const api = "https://type.fit/api/quotes";
let data = await fetch(api);
realData = await data.json();
getNewQuotes();
} catch {
}
};
tweetMe.addEventListener('click',tweetNow)
newQuote.addEventListener("click",getNewQuotes);
getQuotes();