-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
35 lines (29 loc) · 847 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
32
33
34
35
let apiQuotes=[];
var quotetext ={};
var authortext={};
// Show new Quote
function newQuote(){
const randomquote = apiQuotes[Math.floor(Math.random() * apiQuotes.length)];
quotetext = Object.values(randomquote)[0];
authortext = Object.values(randomquote)[1];
document.getElementById("quote").innerHTML=quotetext
document.getElementById("author").innerHTML=authortext
}
//Tweet Quote
function tweetQuote(){
const twitterURL=`https://twitter.com/intent/tweet?text=${quotetext} - ${authortext}`;
window.open(twitterURL);
}
// Get Quotes from API
async function getQuotes(){
const apiUrl='https://jacintodesign.github.io/quotes-api/data/quotes.json';
try {
const response = await fetch(apiUrl);
apiQuotes = await response.json();
newQuote();
// console.log(apiQuotes[12])
} catch(error){
// Catch Error Here
}
}
getQuotes();