-
Notifications
You must be signed in to change notification settings - Fork 0
/
quote_machine.html
92 lines (74 loc) · 3.12 KB
/
quote_machine.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Quote Machine</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/common.css" />
<script>
// https://www.freecodecamp.com/challenges/build-a-random-quote-machine
window.onload = function () {
function ab( num ) {
var a = 0;
return function() {
var b = a;
while (b == a) {
a = getRandomInt ( 0, num );
}
return a;
};
}
function getRandomInt( min, max ) {
min = Math.ceil( min );
max = Math.floor( max );
return Math.floor( Math.random() * (max - min) ) + min;
}
function showQuote() {
var p = int();
var postQuote = el.querySelector( '.b-box__quote' ).textContent = quotes.quote[p][0];
var author = quotes.quote[p][1];
var postAuthor = el.querySelector( '.b-box__name' ).textContent = quotes.names[author];
}
var quotes = {
names : ['Bob Dylan', 'Ludwig van Beethoven', 'Frank Zappa', 'Tom Waits', 'Wolfgang Amadeus Mozart', 'Marilyn Manson'],
quote : [
[ "Jazz isn't dead. It just smells funny.", 2 ],
[ "Behind every beautiful thing, there's some kind of pain.", 0 ],
[ "The music is not in the notes, but in the silence between.", 4 ],
[ "Without deviation from the norm, progress is not possible.", 2 ],
[ "Music is ... A higher revelation than all Wisdom & Philosophy", 1 ],
[ "I like beautiful melodies telling me terrible things.", 3 ],
[ "There ain't no devil, only God when he's drunk.", 3 ],
[ "Music is the strongest form of magic.", 5 ],
[ "A man is a success if he gets up in the morning and gets to bed at night, and in between he does what he wants to do.", 0 ],
[ "Information is not knowledge. Knowledge is not wisdom. Wisdom is not truth. Truth is not beauty. Beauty is not love. Love is not music. Music is the best.", 2 ],
]
};
var el = document.querySelector( '.b-box' );
var bottoms = el.querySelector( '.b-box__footer' );
var twitter = bottoms.firstElementChild;
var newquote = bottoms.lastElementChild;
var num = quotes.quote.length;
var int = ab( num );
newquote.addEventListener( 'click', function( e ) {
e.preventDefault();
showQuote();
});
showQuote();
}
</script>
</head>
<body>
<div class="b-box">
<div class="b-box__quote"></div>
<div class="b-box__name"></div>
<div class="b-box__footer">
<div class="b-box__twitter">
<a href=""></a>
</div>
<div class="b-box__newquote">
<a href="">New quote</a>
</div>
</div>
</div>
</body>
</html>