Skip to content

Commit d390743

Browse files
committed
refactor: standardise code formatting
1 parent af53cd6 commit d390743

File tree

2 files changed

+63
-73
lines changed

2 files changed

+63
-73
lines changed

Sprint-3/quote-generator/app.js

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@ const AUTO_PLAY_INTERVAL_MS = 60000;
88
let 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.
2119
function 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.
3430
function 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.
5347
function 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.
7060
function 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.
9686
displayNewQuote();

Sprint-3/quote-generator/style.css

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/** Write your CSS in here **/
22

33
:root {
4+
--bg-color: #f5ac2d;
5+
--card-bg: #fff;
46
--primary-color: #f5ac2d;
57
--text-color: #f5ac2d;
6-
--bg-color: #f5ac2d;
7-
--card-bg: #ffffff;
88
--transition-speed: 0.3s;
99
}
1010

@@ -15,58 +15,58 @@
1515
}
1616

1717
body {
18-
font-family: Georgia, 'Times New Roman', Times, serif;
18+
align-items: center;
1919
background-color: var(--bg-color);
20-
min-height: 100vh;
2120
display: flex;
21+
font-family: Georgia, 'Times New Roman', Times, serif;
2222
justify-content: center;
23-
align-items: center;
23+
min-height: 100vh;
2424
padding: 1rem;
2525
}
2626

2727
.container {
2828
background: var(--card-bg);
29-
padding: 3rem 4rem;
30-
width: 100%;
29+
/* Applies a simple crisp shadow for visibility, maintaining the flat design aesthetic */
30+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
3131
max-width: 700px;
32-
text-align: center;
32+
padding: 3rem 4rem;
3333
position: relative;
34-
/* Applies a simple crisp shadow for visibility, maintaining the flat design aesthetic */
35-
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
34+
text-align: center;
35+
width: 100%;
3636
}
3737

3838
h1 {
3939
display: none; /* Hides the title as it is not visible in the reference design */
4040
}
4141

4242
#quote {
43+
color: var(--text-color);
4344
font-size: 1.8rem;
4445
line-height: 1.4;
45-
color: var(--text-color);
4646
margin-bottom: 1.5rem;
47-
position: relative;
4847
padding-left: 3rem; /* Reserves space for the decorative quote icon */
48+
position: relative;
4949
text-align: left;
5050
}
5151

5252
#quote::before {
53+
color: var(--primary-color);
5354
content: '“'; /* Renders a large curved quote mark */
55+
font-family: sans-serif; /* Uses sans-serif for the quote mark for better visual appeal */
5456
font-size: 6rem;
55-
color: var(--primary-color);
56-
position: absolute;
57-
top: -1.5rem;
5857
left: -1rem;
5958
line-height: 1;
60-
font-family: sans-serif; /* Uses sans-serif for the quote mark for better visual appeal */
6159
opacity: 1; /* Maintains solid opacity matching the design */
60+
position: absolute;
61+
top: -1.5rem;
6262
}
6363

6464
#author {
65-
font-size: 1.1rem;
6665
color: var(--text-color);
66+
font-size: 1.1rem;
67+
font-style: italic; /* Applies italics to distinguish the author name */
6768
margin-bottom: 2.5rem;
6869
text-align: right;
69-
font-style: italic; /* Applies italics to distinguish the author name */
7070
}
7171

7272
/* Appends a dash before the author name if not dynamically added by JS */
@@ -75,21 +75,21 @@ h1 {
7575
}
7676

7777
.controls {
78+
align-items: flex-end; /* Aligns controls to the right to match typical progression flows */
7879
display: flex;
7980
flex-direction: column;
80-
align-items: flex-end; /* Aligns controls to the right to match typical progression flows */
8181
}
8282

8383
button {
8484
background-color: var(--primary-color);
85-
color: white;
8685
border: none;
87-
padding: 0.8rem 1.5rem;
88-
font-size: 1rem;
89-
font-family: Arial, sans-serif;
86+
color: #fff;
9087
cursor: pointer;
91-
transition: opacity var(--transition-speed) ease;
88+
font-family: Arial, sans-serif;
89+
font-size: 1rem;
9290
font-weight: bold;
91+
padding: 0.8rem 1.5rem;
92+
transition: opacity var(--transition-speed) ease;
9393
}
9494

9595
button:hover {
@@ -98,54 +98,54 @@ button:hover {
9898

9999
/* Auto-play Switch - adjusts layout to fit the theme */
100100
.auto-play-container {
101-
display: flex;
102101
align-items: center;
102+
align-self: flex-end;
103+
display: flex;
103104
gap: 1rem;
104105
margin-top: 1rem; /* Separates the switch from the main action button */
105-
align-self: flex-end;
106106
}
107107

108108
.switch-label {
109-
font-weight: normal;
110-
font-size: 0.9rem;
111109
color: var(--text-color);
112110
font-family: Arial, sans-serif;
111+
font-size: 0.9rem;
112+
font-weight: normal;
113113
}
114114

115115
.switch {
116-
position: relative;
117116
display: inline-block;
118-
width: 50px;
119117
height: 26px;
118+
position: relative;
119+
width: 50px;
120120
}
121121

122122
.switch input {
123+
height: 0;
123124
opacity: 0;
124125
width: 0;
125-
height: 0;
126126
}
127127

128128
.slider {
129-
position: absolute;
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 */
131+
bottom: 0;
130132
cursor: pointer;
131-
top: 0;
132133
left: 0;
134+
position: absolute;
133135
right: 0;
134-
bottom: 0;
135-
background-color: #e4e4e4; /* Sets light grey background for the 'off' state */
136+
top: 0;
136137
transition: .4s;
137-
border-radius: 0; /* Maintains square/rectangular shape for a standard toggle look */
138138
}
139139

140140
.slider:before {
141-
position: absolute;
142-
content: "";
141+
background-color: #fff;
142+
bottom: 3px;
143+
content: '';
143144
height: 20px;
144-
width: 20px;
145145
left: 3px;
146-
bottom: 3px;
147-
background-color: white;
146+
position: absolute;
148147
transition: .4s;
148+
width: 20px;
149149
}
150150

151151
input:checked + .slider {
@@ -161,15 +161,15 @@ input:checked + .slider:before {
161161
}
162162

163163
.status-indicator {
164+
align-self: flex-end;
165+
color: var(--primary-color);
166+
font-family: Arial, sans-serif;
164167
font-size: 0.8rem;
165168
font-weight: bold;
166-
color: var(--primary-color);
167-
opacity: 0;
168169
margin-top: 0.5rem;
169-
align-self: flex-end;
170-
font-family: Arial, sans-serif;
170+
opacity: 0;
171171
}
172172

173173
.status-indicator.active {
174174
opacity: 1;
175-
}
175+
}

0 commit comments

Comments
 (0)