-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
64 lines (54 loc) · 1.95 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
"use strict";
const quote = document.querySelector(".js-quote");
const author = document.querySelector(".js-author");
const quoteButton = document.querySelector(".js-quote-button");
const container = document.querySelector(".js-container");
const mainContainer = document.querySelector(".js-main");
const getQuote = () => {
fetch("https://api.quotable.io/random")
.then(function (response) {
return response.json();
})
.then(function (data) {
renderQuotes(data);
})
.catch((error) => console.log(error));
};
const generateClassNumber = (max) => {
return Math.ceil(Math.random() * max);
};
const renderQuotes = (data) => {
quote.innerHTML = data.content;
quote.id = data._id;
author.innerHTML = data.author;
quote.classList.add("animate__bounceIn");
quote.classList.remove("animate__bounceOut");
author.classList.add("animate__bounceIn");
author.classList.remove("animate__bounceOut");
mainContainer.classList.add(`main-${generateClassNumber(10)}`);
quoteButton.classList.add(`main-${generateClassNumber(10)}`);
quote.classList.add(`letter-color-${generateClassNumber(10)}`);
author.classList.add(`letter-color-${generateClassNumber(10)}`);
};
const changeAnimation = () => {
quote.classList.add("animate__bounceOut");
quote.classList.remove("animate__bounceIn");
author.classList.add("animate__bounceOut");
author.classList.remove("animate__bounceIn");
};
const changeColors = () => {
console.log(mainContainer.classList);
mainContainer.classList.remove(mainContainer.classList.item(1));
quoteButton.classList.remove(quoteButton.classList.item(2));
quote.classList.remove(quote.classList.item(1));
author.classList.remove(author.classList.item(2));
};
const handleClick = () => {
console.log(generateClassNumber(10));
getQuote();
changeAnimation();
changeColors();
};
getQuote();
quoteButton.addEventListener("click", handleClick);
//.item()