@@ -8,16 +8,14 @@ const AUTO_PLAY_INTERVAL_MS = 60000;
88let autoPlayIntervalId = null ;
99
1010// Caches DOM references to avoid repeated lookups during runtime.
11- const quoteElement = document . getElementById ( " quote" ) ;
12- const authorElement = document . getElementById ( " author" ) ;
13- const newQuoteButton = document . getElementById ( " new-quote" ) ;
14- const autoPlaySwitch = document . getElementById ( " auto-play-switch" ) ;
15- const autoPlayStatus = document . getElementById ( " auto-play-status" ) ;
11+ const quoteElement = document . getElementById ( ' quote' ) ;
12+ const authorElement = document . getElementById ( ' author' ) ;
13+ const newQuoteButton = document . getElementById ( ' new-quote' ) ;
14+ const autoPlaySwitch = document . getElementById ( ' auto-play-switch' ) ;
15+ const autoPlayStatus = document . getElementById ( ' auto-play-status' ) ;
1616
17- /**
18- * Retrieves a random quote from the data source and updates the DOM.
19- * Updates both the quote text and the author name.
20- */
17+ // Retrieves a random quote from the data source and updates the DOM.
18+ // Updates both the quote text and the author name.
2119function displayNewQuote ( ) {
2220 // Selects a random quote object from the global 'quotes' array.
2321 const randomQuote = pickFromArray ( quotes ) ;
@@ -27,29 +25,25 @@ function displayNewQuote() {
2725 authorElement . innerText = randomQuote . author ;
2826}
2927
30- /**
31- * Initiates the auto-play feature.
32- * Establishes a recurring timer to refresh the displayed quote.
33- */
28+ // Initiates the auto-play feature.
29+ // Establishes a recurring timer to refresh the displayed quote.
3430function startAutoPlay ( ) {
3531 // Clears any existing timer to prevent overlapping intervals.
3632 if ( autoPlayIntervalId ) {
3733 clearInterval ( autoPlayIntervalId ) ;
3834 }
3935
4036 // Activates the visual status indicator for auto-play.
41- autoPlayStatus . classList . add ( " active" ) ;
37+ autoPlayStatus . classList . add ( ' active' ) ;
4238
4339 // Schedules the 'displayNewQuote' function to execute every 60 seconds.
4440 autoPlayIntervalId = setInterval ( function ( ) {
4541 displayNewQuote ( ) ;
4642 } , AUTO_PLAY_INTERVAL_MS ) ;
4743}
4844
49- /**
50- * Terminates the auto-play feature.
51- * Clears the active timer and resets the state.
52- */
45+ // Terminates the auto-play feature.
46+ // Clears the active timer and resets the state.
5347function stopAutoPlay ( ) {
5448 // Verifies if a timer exists before attempting to clear it.
5549 if ( autoPlayIntervalId ) {
@@ -58,15 +52,11 @@ function stopAutoPlay() {
5852 }
5953
6054 // Deactivates the visual status indicator.
61- autoPlayStatus . classList . remove ( " active" ) ;
55+ autoPlayStatus . classList . remove ( ' active' ) ;
6256}
6357
64- /**
65- * Manages the state change when the auto-play switch is toggled.
66- * Routes execution to start or stop auto-play based on the switch state.
67- *
68- * @param {Event } event - The change event triggered by the checkbox.
69- */
58+ // Manages the state change when the auto-play switch is toggled.
59+ // Routes execution to start or stop auto-play based on the switch state.
7060function handleAutoPlayToggle ( event ) {
7161 // Evaluates the checked state of the toggle switch.
7262 if ( event . target . checked ) {
@@ -78,7 +68,7 @@ function handleAutoPlayToggle(event) {
7868
7969// Attaches a click event listener to the "New quote" button.
8070// Triggers a manual update of the quote and resets the auto-play timer if active.
81- newQuoteButton . addEventListener ( " click" , function ( ) {
71+ newQuoteButton . addEventListener ( ' click' , function ( ) {
8272 displayNewQuote ( ) ;
8373
8474 // Restarts the auto-play timer if the feature is currently enabled.
@@ -90,7 +80,7 @@ newQuoteButton.addEventListener("click", function () {
9080
9181// Attaches a change event listener to the auto-play toggle switch.
9282// Invokes the handler function whenever the user interacts with the switch.
93- autoPlaySwitch . addEventListener ( " change" , handleAutoPlayToggle ) ;
83+ autoPlaySwitch . addEventListener ( ' change' , handleAutoPlayToggle ) ;
9484
9585// Initializes the view by displaying a random quote upon page load.
9686displayNewQuote ( ) ;
0 commit comments