-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
54 lines (47 loc) · 1.75 KB
/
script.js
File metadata and controls
54 lines (47 loc) · 1.75 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
45
46
47
48
49
50
51
52
53
54
const quotes = [
{
text: "Life isn’t about getting and having, it’s about giving and being.",
author: "Kevin Kruse"
},
{
text: "Whatever the mind of man can conceive and believe, it can achieve.",
author: "Napoleon Hill"
},
{
text: "Strive not to be a success, but rather to be of value.",
author: "Albert Einstein"
},
{
text: "You miss 100% of the shots you don’t take.",
author: "Wayne Gretzky"
},
{
text: "I attribute my success to this: I never gave or took any excuse.",
author: "Florence Nightingale"
},
{
text: "You only live once, but if you do it right, once is enough.",
author: "Mae West"
},
];
const getRandomQuote = () => quotes[Math.floor(Math.random() * quotes.length)];
const textElement = document.getElementById('text');
const authorElement = document.getElementById('author');
const tweetButton = document.getElementById('tweet-quote');
const newQuoteButton = document.getElementById('new-quote');
// On page load, display a random quote
let currentQuote = getRandomQuote();
textElement.textContent = `"${currentQuote.text}"`;
authorElement.textContent = `- ${currentQuote.author}`;
// Update the quote when the button is clicked
const updateQuote = () => {
currentQuote = getRandomQuote();
textElement.textContent = `"${currentQuote.text}"`;
authorElement.textContent = `- ${currentQuote.author}`;
// Update the tweet link
tweetButton.href = `https://twitter.com/intent/tweet?text=${encodeURIComponent(
`"${currentQuote.text}" - ${currentQuote.author}`
)}`;
};
// Event listener for the "New Quote" button
newQuoteButton.addEventListener('click', updateQuote);