Skip to content

Commit 307b98e

Browse files
committed
refactor: remove unnecessary comments
1 parent d390743 commit 307b98e

File tree

2 files changed

+13
-52
lines changed

2 files changed

+13
-52
lines changed

Sprint-3/quote-generator/app.js

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,52 @@
11
/* globals quotes, pickFromArray */
22

3-
// Defines the auto-play interval duration (60 seconds) as a constant for maintainability.
43
const AUTO_PLAY_INTERVAL_MS = 60000;
5-
6-
// Tracks the state of the auto-play timer.
7-
// Initializes as null to indicate no active timer.
84
let autoPlayIntervalId = null;
95

10-
// Caches DOM references to avoid repeated lookups during runtime.
116
const quoteElement = document.getElementById('quote');
127
const authorElement = document.getElementById('author');
138
const newQuoteButton = document.getElementById('new-quote');
149
const autoPlaySwitch = document.getElementById('auto-play-switch');
1510
const autoPlayStatus = document.getElementById('auto-play-status');
1611

17-
// Retrieves a random quote from the data source and updates the DOM.
18-
// Updates both the quote text and the author name.
1912
function displayNewQuote() {
20-
// Selects a random quote object from the global 'quotes' array.
2113
const randomQuote = pickFromArray(quotes);
22-
23-
// Updates the HTML elements with the new quote text and author name.
2414
quoteElement.innerText = randomQuote.quote;
2515
authorElement.innerText = randomQuote.author;
2616
}
2717

28-
// Initiates the auto-play feature.
29-
// Establishes a recurring timer to refresh the displayed quote.
3018
function startAutoPlay() {
31-
// Clears any existing timer to prevent overlapping intervals.
3219
if (autoPlayIntervalId) {
3320
clearInterval(autoPlayIntervalId);
3421
}
35-
36-
// Activates the visual status indicator for auto-play.
3722
autoPlayStatus.classList.add('active');
38-
39-
// Schedules the 'displayNewQuote' function to execute every 60 seconds.
40-
autoPlayIntervalId = setInterval(function () {
41-
displayNewQuote();
42-
}, AUTO_PLAY_INTERVAL_MS);
23+
autoPlayIntervalId = setInterval(displayNewQuote, AUTO_PLAY_INTERVAL_MS);
4324
}
4425

45-
// Terminates the auto-play feature.
46-
// Clears the active timer and resets the state.
4726
function stopAutoPlay() {
48-
// Verifies if a timer exists before attempting to clear it.
4927
if (autoPlayIntervalId) {
5028
clearInterval(autoPlayIntervalId);
5129
autoPlayIntervalId = null;
5230
}
53-
54-
// Deactivates the visual status indicator.
5531
autoPlayStatus.classList.remove('active');
5632
}
5733

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.
6034
function handleAutoPlayToggle(event) {
61-
// Evaluates the checked state of the toggle switch.
6235
if (event.target.checked) {
6336
startAutoPlay();
6437
} else {
6538
stopAutoPlay();
6639
}
6740
}
6841

69-
// Attaches a click event listener to the "New quote" button.
70-
// Triggers a manual update of the quote and resets the auto-play timer if active.
7142
newQuoteButton.addEventListener('click', function () {
7243
displayNewQuote();
73-
74-
// Restarts the auto-play timer if the feature is currently enabled.
75-
// Ensures the full interval elapses before the next automatic update.
7644
if (autoPlaySwitch.checked) {
7745
startAutoPlay();
7846
}
7947
});
8048

81-
// Attaches a change event listener to the auto-play toggle switch.
82-
// Invokes the handler function whenever the user interacts with the switch.
8349
autoPlaySwitch.addEventListener('change', handleAutoPlayToggle);
8450

85-
// Initializes the view by displaying a random quote upon page load.
86-
displayNewQuote();
51+
// Initial display on load.
52+
displayNewQuote();

Sprint-3/quote-generator/style.css

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/** Write your CSS in here **/
2-
31
:root {
42
--bg-color: #f5ac2d;
53
--card-bg: #fff;
@@ -26,7 +24,6 @@ body {
2624

2725
.container {
2826
background: var(--card-bg);
29-
/* Applies a simple crisp shadow for visibility, maintaining the flat design aesthetic */
3027
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
3128
max-width: 700px;
3229
padding: 3rem 4rem;
@@ -36,46 +33,45 @@ body {
3633
}
3734

3835
h1 {
39-
display: none; /* Hides the title as it is not visible in the reference design */
36+
display: none;
4037
}
4138

4239
#quote {
4340
color: var(--text-color);
4441
font-size: 1.8rem;
4542
line-height: 1.4;
4643
margin-bottom: 1.5rem;
47-
padding-left: 3rem; /* Reserves space for the decorative quote icon */
44+
padding-left: 3rem; /* Space for quote icon. */
4845
position: relative;
4946
text-align: left;
5047
}
5148

5249
#quote::before {
5350
color: var(--primary-color);
54-
content: '“'; /* Renders a large curved quote mark */
55-
font-family: sans-serif; /* Uses sans-serif for the quote mark for better visual appeal */
51+
content: '“';
52+
font-family: sans-serif;
5653
font-size: 6rem;
5754
left: -1rem;
5855
line-height: 1;
59-
opacity: 1; /* Maintains solid opacity matching the design */
56+
opacity: 1;
6057
position: absolute;
6158
top: -1.5rem;
6259
}
6360

6461
#author {
6562
color: var(--text-color);
6663
font-size: 1.1rem;
67-
font-style: italic; /* Applies italics to distinguish the author name */
64+
font-style: italic;
6865
margin-bottom: 2.5rem;
6966
text-align: right;
7067
}
7168

72-
/* Appends a dash before the author name if not dynamically added by JS */
7369
#author::before {
7470
content: '- ';
7571
}
7672

7773
.controls {
78-
align-items: flex-end; /* Aligns controls to the right to match typical progression flows */
74+
align-items: flex-end;
7975
display: flex;
8076
flex-direction: column;
8177
}
@@ -96,13 +92,12 @@ button:hover {
9692
opacity: 0.9;
9793
}
9894

99-
/* Auto-play Switch - adjusts layout to fit the theme */
10095
.auto-play-container {
10196
align-items: center;
10297
align-self: flex-end;
10398
display: flex;
10499
gap: 1rem;
105-
margin-top: 1rem; /* Separates the switch from the main action button */
100+
margin-top: 1rem;
106101
}
107102

108103
.switch-label {
@@ -126,8 +121,8 @@ button:hover {
126121
}
127122

128123
.slider {
129-
background-color: #e4e4e4; /* Sets light grey background for the 'off' state */
130-
border-radius: 0; /* Maintains square/rectangular shape for a standard toggle look */
124+
background-color: #e4e4e4;
125+
border-radius: 0;
131126
bottom: 0;
132127
cursor: pointer;
133128
left: 0;

0 commit comments

Comments
 (0)