-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
33 lines (26 loc) · 855 Bytes
/
script.js
File metadata and controls
33 lines (26 loc) · 855 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
26
27
28
29
30
31
32
33
let authorEle=document.getElementById("author");
let textEle=document.getElementById("text");
let button=document.getElementById("button");
let quotearr=[];
let index=0;
button.addEventListener("click",displayQuotes);
function displayQuotes() {
index=Math.floor(Math.random()*quotearr.length);
console.log(index);
textEle.textContent=quotearr[index].text;
authorEle.innerHTML=`<strong> —${quotearr[index].author}</strong>`;
fetchquotes(index)
}
async function fetchquotes(index){
let url="https://jacintodesign.github.io/quotes-api/data/quotes.json";
try{
let response=await fetch(url)
let data= await response.json()
console.log(data)
quotearr=data;
}
catch(error){
console.log(error)
}
}
fetchquotes(index);