Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Sprint-3/quote-generator/quotes.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
document.addEventListener("DOMContentLoaded", () => {
const {quote, author} = pickFromArray(quotes);
document.getElementById("quote").innerText = quote;
document.getElementById("author").innerText = author;
Comment on lines +2 to +4

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice that the logic for choosing a random quote and updating the quote and author elements appears twice: once in the DOMContentLoaded handler and once in the button click handler. If you ever need to change how a quote is picked or how it is displayed (for example, changing the DOM element IDs or adding extra formatting), you would need to remember to update both places and keep them in sync.

How would it feel to extract those three lines into a small function, and then call that function from both event listeners? That way the behavior for “show a new quote” would live in exactly one place, and both the initial load and the button click would just reuse it. This can make the code easier to maintain and test as the project grows.

To "like" or "dislike" this comment, please follow this link

});

document.querySelector("button").addEventListener("click", () => {
const {quote, author} = pickFromArray(quotes);
document.getElementById("quote").innerText = quote;
document.getElementById("author").innerText = author;
});

// DO NOT EDIT BELOW HERE

// pickFromArray is a function which will return one item, at
Expand Down
Loading