-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
98 lines (81 loc) · 2.38 KB
/
index.js
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// document.querySelector("body").style.background = "url('images/image (' + $randomNumber + ').jpg')"
// $("body").css("background-image", "url('images/image ($).jpg')")
const quoteText = document.querySelector(".quote");
const authorText = document.querySelector(".author");
const twitterButton = document.querySelector(".twitter-btn");
const nextQuoteButton = document.querySelector(".next-quote-btn");
const quoteBox = document.querySelector(".quote-box");
const colors = [
'#490A3D',
'#BD1550',
'#E97F02',
'#F8CA00',
'#8A9B0F',
'#69D2E7',
'#FA6900',
'#16a085',
'#27ae60',
'#2c3e50',
'#f39c12',
'#e74c3c',
'#9b59b6',
'#FB6964',
'#342224',
'#472E32',
'#77B1A9',
'#73A857',
"red",
"blue",
"green",
"yellow",
"orange",
"green",
"purple",
"yellowgreen",
"greenyellow",
"magenta",
"cyan",
"aqua",
"violet",
"hotpink",
"pink",
"olive",
"skyblue",
"navy",
"royalblue",
"lime",
"turquoise",
"maroon"
];
// const mydata = JSON.parse(data);
// console.log(mydata.length);
// alert(mydata.length)
nextQuoteButton.addEventListener("click", function () {
let data;
let randomNumberColors;
let randomNumberQuote;
fetch('data.json')
.then(response => response.json())
.then(data => {
// Do something with your data
// console.log(data);
const dataLength = data.length;
randomNumberQuote = Math.floor(Math.random() * dataLength) + 1;
console.log(randomNumberQuote);
const colorsLength = colors.length;
randomNumberColors = Math.floor(Math.random() * colorsLength) + 1;
// console.log(randomNumberColors);
// console.log(data[1]);
// console.log(data);
const quote = data[randomNumberQuote].text;
// console.log(quote);
const author = data[randomNumberQuote].author;
const color = colors[randomNumberColors];
quoteText.innerHTML = quote;
authorText.innerHTML = "— " + author;
document.querySelector("body").style.backgroundColor = color;
twitterButton.style.backgroundColor = color;
nextQuoteButton.style.backgroundColor = color;
quoteBox.style.borderLeft = `10px solid ${color}`;
});
});