Skip to content

Commit dab1b08

Browse files
committed
write function for quote generator
1 parent 4222cda commit dab1b08

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

‎Sprint-3/quote-generator/index.html‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
<head>
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6-
<title>Title here</title>
6+
<title>Quote generator app</title>
77
<script defer src="quotes.js"></script>
88
</head>
99
<body>
10-
<h1>hello there</h1>
11-
<p id="quote"></p>
12-
<p id="author"></p>
10+
<h1>Quote Generator</h1>
11+
<p id="quote">Quote:</p>
12+
<p id="author">Author:</p>
1313
<button type="button" id="new-quote">New quote</button>
1414
</body>
1515
</html>

‎Sprint-3/quote-generator/quotes.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,3 +491,19 @@ const quotes = [
491491
];
492492

493493
// call pickFromArray with the quotes array to check you get a random quote
494+
console.log(pickFromArray(quotes));
495+
496+
// 1. get a button variable.
497+
// 2. listen to the event.
498+
// 3, when event happens produce a quote in one place <p>
499+
//4. when an event happens produce author of that quote in the other <p>
500+
const button = document.querySelector("#new-quote");
501+
function newQuoteEveryTime() {
502+
const quote = pickFromArray(quotes);
503+
const quotePlace = document.querySelector("#quote");
504+
const authorPlace = document.querySelector("#author");
505+
quotePlace.innerText = `The quote of the day is: ${quote.quote}`;
506+
authorPlace.innerText = `By the author - ${quote.author}`;
507+
}
508+
509+
button.addEventListener("mousedown", newQuoteEveryTime);

0 commit comments

Comments
 (0)