-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
53 lines (36 loc) · 1.77 KB
/
app.js
File metadata and controls
53 lines (36 loc) · 1.77 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var btn = document.querySelector('#btn-click');
var output = document.querySelector('#output');
// var serverUrl = "https://api.adviceslip.com/advice";
var serverUrl = "https://quote-garden.herokuapp.com/api/v2/quotes/random";
function isOnline() {
if (!navigator.onLine) {
document.getElementById("#output").innerText = "Online";
} else {
document.getElementById("#output").innerText = "Offline";
}
}
function errorHandler(error){
return( "server Error" + error);
}
function process(){
if(navigator.onLine){
// var textInput = txt.value
console.log("clicked")
fetch(serverUrl).then(respone => respone.json()).then( json => {
// var outputText = json.slip.advice;
var quoteText = json.quote.quoteText;
var quoteAuthor = json.quote.quoteAuthor;
outputText = quoteText + "<br>"+ "---" + quoteAuthor;
output.innerHTML = outputText
console.log(outputText);
console.log(quoteAuthor)
}
).catch(errorHandler)
}
else{
var outputText = "Please!! Connect To Internet.. ,You are offline......";
output.innerText = outputText
output.style.color = 'green';
}
}
btn.addEventListener('click',process);