forked from pbaesse/quotebox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
27 lines (18 loc) · 646 Bytes
/
script.js
File metadata and controls
27 lines (18 loc) · 646 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
let JSON_SOURCE = window.location.protocol + "//" + window.location.hostname + "/quotes.json"
let fetchJSON = (a) => {
let f=new XMLHttpRequest;
f.open("GET",a,false);
f.send(null);
return f.responseText
}
let quotes = JSON.parse(fetchJSON(JSON_SOURCE))
let setQuote = () =>{
let QuoteRandomNumber = Math.floor(Math.random() * quotes.length)
let randomQuote = quotes[QuoteRandomNumber]
document.getElementById("quote-body").innerText = randomQuote.quote;
document.getElementById("quote-speaker").innerText = "~" +randomQuote.speaker;
}
document.getElementById("inspireme").onclick = function(){
setQuote();
}
setQuote();