Skip to content

Conversation

@Konvaly
Copy link

@Konvaly Konvaly commented Dec 5, 2025

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

This PR completes and extends the original Quote Generator task.
It implements all required functionality (displaying random quotes, updating on button click) and adds an enhanced auto-play mode.
Additionally, the UI has been redesigned.

Key updates:

  • Implemented the core Quote Generator logic (random quote on load + on button click)

  • Added auto-play toggle to generate new quotes automatically

  • Added interval-based auto-generation with start/stop control

  • Displayed “auto-play: ON/OFF” status dynamically

  • Improved styling in CSS-file

@Konvaly Konvaly added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Dec 5, 2025
const autoPlayToggle = document.getElementById("auto-play-toggle");
const autoPlayStatus = document.getElementById("auto-play-status");

newQuoteBtn.addEventListener("click", showRandomQuote);

Choose a reason for hiding this comment

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

what happens if quoteEl, authorEl, newQuoteBtn, autoPlayToggle, autoPlayStatus or their corresponding ids are not available, missing, not spelled correctly?

Copy link
Author

Choose a reason for hiding this comment

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

If newQuoteBtn is null, then JavaScript will try to run : "null.addEventListener(...)"
This causes a TypeError (Cannot read properties of null (reading 'addEventListener')), therefore it stops the script, so the whole quote generator will break.
I fixed it with adding helper function which checks if element exist and throws a mistake if not.

display: inline-block;
}

.auto-play-label {

Choose a reason for hiding this comment

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

is there a way to use the DRY principle between the label and the .auto-play-label? since they both have label ?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the feedback! I updated the CSS so the shared label styles are all in the main label rule.
.auto-play-label now only overrides what’s different (the margin and slightly smaller gap), so it’s more DRY.

autoPlayToggle.addEventListener("click", () => {
if (autoPlayToggle.checked) {
autoPlayStatus.innerText = "auto-play: ON";
autoPlayInterval = setInterval(showRandomQuote, 4000);

Choose a reason for hiding this comment

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

what happens if interval has been set and not cleared before the above line ?

Copy link
Author

Choose a reason for hiding this comment

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

If the interval isn’t cleared, a new setInterval creates an extra timer, so multiple intervals run at once. I fixed this by clearing the existing interval before starting a new one.

@JaypeeLan JaypeeLan added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Dec 7, 2025

Choose a reason for hiding this comment

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

Everything works well, but there is an improvement to make. I noticed as I got new quotes, some quotes are quite long, so the height of the container keeps adjusting, and I have to move my cursor everytime that happens. So, what you can do is figure out how you can keep the height of the container, so the next button stays in its position. Maybe use ellipsis and a "show more" button if the quote is too long. Be creative.
When you have cards that displays a list of content, you have to keep the height uniform.

Copy link
Author

Choose a reason for hiding this comment

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

Hi @JaypeeLan, thanks for pointing that out! I noticed the layout shifting with longer quotes too. I updated the card so it keeps a consistent height, which stops the button from moving around. For quotes that are really long, I added an ellipsis and a “Show more / Show less” toggle, truncated to 2 lines. This way the layout stays steady, but users can still read the full quote if they want to.

@JaypeeLan JaypeeLan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Dec 7, 2025
@Konvaly Konvaly added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Dec 10, 2025
@Konvaly
Copy link
Author

Konvaly commented Dec 10, 2025

Hi @takanocap , @JaypeeLan ! Could you check my PR fixed according to your reviews, please?

Copy link

@takanocap takanocap left a comment

Choose a reason for hiding this comment

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

The unit test could be improved to cover unhappy path and edge cases. please research that but well done for the hard work.
LGTM

@JaypeeLan JaypeeLan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Dec 11, 2025
@Konvaly
Copy link
Author

Konvaly commented Dec 12, 2025

Hi @JaypeeLan , @takanocap ! Thank you for reviewing my PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants