Skip to content

Commit ca4da9b

Browse files
I wrote 3 variables to define the quote, auother, and neq-quote.
- implemented a function to show the randomquotes and wrote an event to update the quote content once the new quote botton clicked.
1 parent 9f9b2b0 commit ca4da9b

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

Sprint-3/quote-generator/index.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>Quote generator app</title>
77
<script defer src="quotes.js"></script>
8+
<link rel="stylesheet" href="style.css">
89
</head>
910
<body>
10-
<h1>Quote generator</h1>
11-
<p id="quote"></p>
12-
<p id="author"></p>
13-
<button type="button" id="new-quote">New quote</button>
11+
<h1>Quote Generator</h1>
12+
<p id="quote"></p>
13+
<p id="author"></p>
14+
<button type="button" id="new-quote">New quote</button>
15+
</div>
1416
</body>
1517
</html>

Sprint-3/quote-generator/quotes.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
// Examples of use
1515
// ---------------
1616
// pickFromArray(['a','b','c','d']) // maybe returns 'c'
17-
17+
const quote = document.querySelector("#quote");
18+
const author = document.querySelector("#author");
19+
const newquote = document.querySelector("#new-quote");
1820
// You don't need to change this function
19-
function pickFromArray(choices) {
20-
return choices[Math.floor(Math.random() * choices.length)];
21+
function pickFromArray(quotes) {
22+
return quotes[Math.floor(Math.random() * quotes.length)];
2123
}
2224

2325
// A list of quotes you can use in your app.
@@ -491,3 +493,14 @@ const quotes = [
491493
];
492494

493495
// call pickFromArray with the quotes array to check you get a random quote
496+
function showRandomQuote() {
497+
const randomQuote = pickFromArray(quotes);
498+
quote.textContent = randomQuote.quote;
499+
author.textContent = randomQuote.author;
500+
}
501+
// show one on load
502+
showRandomQuote();
503+
// change quote on click:
504+
quote.addEventListener("click", showRandomQuote);
505+
author.addEventListener("click", showRandomQuote);
506+
newquote.addEventListener("click", showRandomQuote);

Sprint-3/quote-generator/style.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
/** Write your CSS in here **/

0 commit comments

Comments
 (0)