-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
66 lines (51 loc) · 1.79 KB
/
app.js
File metadata and controls
66 lines (51 loc) · 1.79 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const quote = document.querySelector('.quote');
const author = document.querySelector('.author');
//previous and next buttons
const prev = document.getElementById("prev");
const next = document.getElementById("next");
function test() {
fetch("https://type.fit/api/quotes")
.then(function(response) {
return response.json();
})
.then(function(data) {
var random = data[Math.floor(Math.random() * data.length)];
quote.textContent = random.text;
if(random.author == null) {
author.textContent = " Written By - Anonymous";
} else {
author.textContent = "Written By " + random.author;
}
});
}
test();
var nClicks = 0;
var pClicks = 0
function change() {
fetch("https://type.fit/api/quotes")
.then(function(response) {
return response.json();
})
.then(function(data) {
var random = Math.floor(Math.random() * data.length);
console.log(data.indexOf(data[random]))
quote.textContent = data[random].text;
random.author == null ? author.textContent = " Written By - Anonymous": author.textContent = "Written By - " + data[random].author;
next.style.opacity = "1";
prev.style.opacity = "1";
next.addEventListener("click", function() {
random++;
quote.textContent = data[random].text;
random.author == null ? author.textContent = " Written By - Anonymous": author.textContent = "Written By - " + data[random].author;
console.log(data.indexOf(data[random]))
})
prev.addEventListener("click", function() {
random--;
if(data.indexOf(data[random]) !== -1) {
quote.textContent = data[random].text;
random.author == null ? author.textContent = " Written By - Anonymous": author.textContent = "Written By - " + data[random].author;
console.log(data.indexOf(data[random]))
}
})
});
}