-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
50 lines (43 loc) · 1.69 KB
/
script.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
const authorEl = document.querySelector(".author");
const quoteEl = document.querySelector(".quote");
const profile = document.querySelector(".profile");
const generate = document.querySelector(".generate");
const apiURL = 'https://api.breakingbadquotes.xyz/v1/quotes';
function generateQuote() {
quoteEl.innerHTML = '';
generate.disabled = true;
fetch(apiURL)
.then(res => res.json())
.then(resData => {
const author = resData[0].author;
const quote = resData[0].quote;
let i = 0;
const intrval = setInterval(() => {
quoteEl.innerHTML += quote[i];
i++;
if(i == quote.length) {
clearInterval(intrval);
generate.disabled = false
}
}, 50)
authorEl.innerHTML = author;
if(author.toLowerCase() == "jesse pinkman") {
profile.src = "./images/jesse.jpg";
} else if(author.toLowerCase() == "gustavo fring") {
profile.src = "./images/gus.jpg";
} else if(author.toLowerCase() == "walter white") {
profile.src = "./images/walter.jpg";
} else if(author.toLowerCase() == "hank schrader") {
profile.src = "./images/hank.jpg";
} else if(author.toLowerCase() == "skyler white") {
profile.src = "./images/skyler.jpg";
} else if(author.toLowerCase() == "saul goodman") {
profile.src = "./images/saulgoodman.jpg";
profile.style.objectPosition = "top";
} else if(author.toLowerCase() == "mike ehrmantraut") {
profile.src = "./images/mike.jpg";
}
});
}
generateQuote();
generate.addEventListener('click', generateQuote)