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
10 changes: 10 additions & 0 deletions Sprint-3/quote-generator/quotes.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
const showNewQuote = () => {
const {quote, author} = pickFromArray(quotes);
document.getElementById("quote").innerText = quote;
document.getElementById("author").innerText = author;
};

document.addEventListener("DOMContentLoaded", () => { showNewQuote(); });

document.querySelector("button").addEventListener("click", () => { showNewQuote(); });
Comment on lines +7 to +9

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

On the two event listeners, you’re wrapping showNewQuote in an arrow function that only calls showNewQuote and doesn’t do anything else. Since those arrow functions don’t add any extra logic or clarity, they’re effectively “temporary” functions used once before their immediate use.

In cases like this, you might ask yourself: does this wrapper help readability or behavior in any way, or could I just pass the existing function directly? Here, passing showNewQuote directly would avoid creating an extra, single-use function while keeping the code easy to read.

The destructuring assignment const {quote, author} = pickFromArray(quotes); is a good use of a temporary value: you need a single random choice from quotes and then use both quote and author separately, so holding that result in a variable actually improves clarity and avoids calling pickFromArray twice.

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


// DO NOT EDIT BELOW HERE

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