-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
44 lines (37 loc) · 1.49 KB
/
Copy pathscript.js
File metadata and controls
44 lines (37 loc) · 1.49 KB
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
const quoteStore = [
{
"quote": "So many books, so little time.",
"author": "Frank Zappa"
}, {
"quote": "Be the change that you wish to see in the world.",
"author": "Mahatma Gandhi"
}, {
"quote": "You know you're in love when you can't fall asleep because reality is finally better than your dreams.",
"author": "Dr. Seuss"
}, {
"quote": "Do one thing every day that scares you.",
"author": "Eleanor Roosevelt"
}, {
"quote": "It is during our darkest moments that we must focus to see the light.",
"author": "Aristotle"
}
];
window.onload = init;
function init() {
displayQuote();
}
function displayQuote() {
let quoteSize = quoteStore.length;
let randomQuote = Math.floor(Math.random() * quoteSize);
let randomQuoteData = quoteStore[randomQuote];
let twitterLink = "https://twitter.com/intent/tweet?hashtags=quotes&related=freecodecamp&text=%22"
// Add quote
let quoteInApiFormat = randomQuoteData.quote.replace(/ /g, "%20");
twitterLink += quoteInApiFormat
// Add author
let authorInApiFormat = randomQuoteData.author.replace(/ /g, "%20");
twitterLink += " - " + authorInApiFormat
document.getElementById("tweet-quote").href = twitterLink;
document.getElementById("text").innerText = randomQuoteData.quote;
document.getElementById("author").innerText = randomQuoteData.author;
}