-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
46 lines (35 loc) · 1.08 KB
/
script.js
File metadata and controls
46 lines (35 loc) · 1.08 KB
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
var qoutes = document.getElementsByClassName('quotes');
var author = document.getElementsByClassName('author');
var button = document.getElementById('button');
let realdata = "";
let quotesdata = "";
let quotesauthor = "";
const newQuotes = () => {
let randomvalue = Math.floor((Math.random() * 1642) + 1);
quotesdata = realdata[randomvalue].text;
qoutes[0].innerHTML = quotesdata;
quotesauthor = realdata[randomvalue].author;
if (quotesauthor == null) {
author[0].innerHTML = "unknown";
}
else {
author[0].innerHTML = quotesauthor +".";
}
}
const getQuotes = async () => {
const api = "https://type.fit/api/quotes";
try {
const data = await fetch(api);
realdata = await data.json();
newQuotes();
} catch (error) {
console.log("error");
}
};
button.addEventListener("click", newQuotes);
twitter.addEventListener("click", () => {
const tweetpost = `https://twitter.com/intent/tweet?text=${quotesdata} ~ ${quotesauthor}`;
console.log(tweetpost)
window.open(tweetpost);
});
getQuotes();