-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
23 lines (21 loc) · 819 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
const api_url = "https://api.api-ninjas.com/v1/quotes?category=health"
const apiKey = 'soP2DeFDH0h3N+n7RWfAiA==7bCg5koQKLpC0Av5'
const quoteElement = document.getElementById("quote");
const authorElement = document.getElementById("author");
async function getQuote(url){
const res = await fetch(url, {
headers: {
'X-Api-Key': apiKey
}
});
const data = await res.json();
console.log(data);
//set innerHTML of the quote element
quoteElement.innerHTML = data[0].quote
// Set theinnerHTML of the author element
authorElement.innerHTML = data[0].author;
}
getQuote(api_url)
function tweet(){
window.open("https://twitter.com/intent/tweet?text=" + quoteElement.innerHTML + " ------ by " + authorElement.innerHTML, "Tweet Window", "width=600, height=400");
}