-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
133 lines (107 loc) · 4.6 KB
/
main.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// ARRAY OF FAMOUS QUOTES
const quotes = [
{
name: "Isaac Newton",
quote: "I seem to have been only like a boy playing on the seashore, and diverting myself in now and then finding a smoother pebble or a prettier shell than ordinary, whilst the great ocean of truth lay all undiscovered before me."
},
{
name: "Albert Einstein",
quote: "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe."
},
{
name: "Fred Hoyle",
quote: "Life cannot have had a random beginning ... The trouble is that there are about 2000 enzymes, and the chance of obtaining them all in a random trial is only one part in 10^40,000, an outrageously small probability that could not be faced even if the whole universe consisted of organic soup."
},
{
name: "Georg C. Lichtenberg",
quote: " It is strange that only extraordinary men make the discoveries, which later appear so easy and simple."
},
{
name: "Nicolaus Copernicus",
quote: "There may be babblers, wholly ignorant of mathematics, who dare to condemn my hypothesis, upon the authority of some part of the Bible twisted to suit their purpose. I value them not, and scorn their unfounded judgment."
},
{
name: "John Archibald Wheeler",
quote: "There is no law except the law that there is no law."
},
{
name: "Stephen Jay Gould",
quote: "We pass through this world but once. Few tragedies can be more extensive than the stunting of life, few injustices deeper than the denial of an opportunity to strive or even to hope, by a limit imposed from without, but falsely identified as lying within."
},
{
name: "Thomas Chrowder Chamberlin",
quote: "Falsity in intellectual action is intellectual immorality."
},
{
name: "Subrahmanyan Chandrasekhar",
quote: "The black holes of nature are the most perfect macroscopic objects there are in the universe: the only elements in their construction are our concepts of space and time."
},
{
name: "Isaac Asimov",
quote: "The saddest aspect of life right now is that gathers knowledge faster than society gathers wisdom."
},
{
name: "Albert Eintein",
quote: "Science without religion is lame, religion without science is blind."
},
{
name: "Charles Darwin",
quote: "A man who dares to waste one hour of time has not discovered the value of life."
},
{
name: "Marie Curie",
quote: "Nothing in life is to be feared, it is only to be understood. Now is the time to understand more, so that we may fear less."
},
{
name: "Galileo Galilei",
quote: "You cannot teach a man anything; you can only help him discover it in himself."
},
{
name: "Isaac Newton",
quote: "If I have seen further it is by standing on the shoulders of Giants."
},
{
name: "Stephen Hawking",
quote: "One, remember to look up at the stars and not down at your feet. Two, never give up work. Work gives you meaning and purpose and life is empty without it. Three, if you are lucky enough to find love, remember it is there and don't throw it away."
}
]
// REFERENCES FOR DOM MANIPULATION
const quoteBtn = document.querySelector('#quote-btn');
const quoteText = document.querySelector('#quote');
const quoteAuthor = document.querySelector('#quote-author');
//create a function getQuotes to fetch the quotes from the given API
const getQuotes = async () => {
const request = await fetch('https://type.fit/api/quotes');
const data = await request.json();
console.log(data);
let randomNumber = Math.floor(Math.random() * data.length);
// console.log(`{quote: ${data[randomNumber].text}
// author: ${data[randomNumber].author}}
// `);
return {
quote: data[randomNumber].text,
author: data[randomNumber].author
};
}
//create a function to update the UI
const updateUI = (data) => {
// Assign variables to the data you want to use
const { quote, author } = data;
console.log(data);
//output this data assigned to the DOM
quoteText.innerHTML = quote;
quoteAuthor.innerHTML = author;
}
// Click event for DOM manipulation
quoteBtn.addEventListener('click', (e) => {
e.preventDefault();
//call the get quotes here with its success/error handler
getQuotes()
.then((data) => {
// console.log(data);
updateUI(data);
})
.catch((error) => {
console.log(error);
});
})