-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
25 lines (25 loc) · 726 Bytes
/
index.js
File metadata and controls
25 lines (25 loc) · 726 Bytes
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
let quote=" "
let author=" "
let qt=" "
let value=" "
function generateQuote(){
const url = 'https://api.api-ninjas.com/v1/quotes?';
const options = {
headers: {
'X-Api-Key': 'YOUR_APIKEY',
}
}
let fetchRes = fetch(url,options);
quote=fetchRes.then(res =>
res.json()).then(quote => {
qt=quote
for (let i = 0; i < qt.length; i++) {
value=qt[i]['quote']
}
for (let i = 0; i < qt.length; i++) {
author=qt[i]['author']
}
document.getElementById("quote").innerHTML=value;
document.getElementById("author").innerHTML=author;
}).catch(error=>console.error('Error fetching quote:',error))
}