-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripts.js
31 lines (25 loc) · 865 Bytes
/
scripts.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 text=document.getElementById("quote");
const author=document.getElementById("author");
const tweetButton=document.getElementById("tweet");
const getNewQuote = async () =>
{
//api for quotes
var url="https://type.fit/api/quotes";
// fetching the data from api
const response=await fetch(url);
console.log(typeof response);
//convert the responses to json and storing in array
const allQuotes = await response.json();
const indx = Math.floor(Math.random()*allQuotes.length);
const quote=allQuotes[indx].text;
const auth=allQuotes[indx].author;
if(auth==null)
{
author = "Anonymous";
}
text.innerHTML=quote;
author.innerHTML="~ "+auth;
//tweet the quote
tweetButton.href="https://twitter.com/intent/tweet?text="+quote+" ~ "+auth;
}
getNewQuote();