Skip to content

Commit 8c5b008

Browse files
a2937jdwilkin4
andauthored
fix(curriculum): more accessible icon picker (freeCodeCamp#59490)
Co-authored-by: Jessica Wilkins <67210629+jdwilkin4@users.noreply.github.com>
1 parent 5a5e5de commit 8c5b008

1 file changed

Lines changed: 66 additions & 62 deletions

File tree

curriculum/challenges/english/25-front-end-development/lab-favorite-icon-toggler/66bf6bacf178eac7b96d4f5e.md

Lines changed: 66 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ Fulfill the user stories below and get all the tests to pass to complete the lab
1818
2. The unordered list should have the class `item-list`.
1919
3. The three list items should contain the item name followed by a `button` element with the class `favorite-icon`.
2020
4. The `button` element should contain the code `&#9825;` initially to represent an empty heart.
21-
5. When a `button` element containing a heart is clicked, you should add the `filled` class to the clicked `button` if it's not already present, and remove it, if it is.
22-
6. When a `button` element containing a heart is clicked, the heart symbol should toggle between `&#9825;` (empty heart) and `&#10084;` (filled heart), depending on its current state.
21+
5. You should create a `filled` class that should contain style information.
22+
6. When a `button` element containing a heart is clicked, you should add the `filled` class to the clicked `button` if it's not already present, and remove it, if it is.
23+
7. When a `button` element containing a heart is clicked, the heart symbol should toggle between `&#9825;` (empty heart) and `&#10084;` (filled heart), depending on its current state.
2324

2425
**Note:** Be sure to link your JavaScript file in your HTML. (Ex. `<script src="script.js"></script>`)
2526

@@ -47,7 +48,6 @@ Your individual list items should contain the item name.
4748

4849
```js
4950
assert.exists(document.querySelector('ul li').textContent);
50-
5151
```
5252

5353
Your individual list item should contain a `button` element with the class `favorite-icon`.
@@ -60,13 +60,21 @@ Initially, the `button` elements should contain the code `&#9825;` to represent
6060

6161
```js
6262
const inputs = document.querySelectorAll('ul li button.favorite-icon');
63-
assert.isNotEmpty(inputs)
63+
assert.isNotEmpty(inputs);
6464

6565
for (let input of inputs) {
66-
assert.strictEqual(input.innerHTML.charCodeAt(0), 9825);
66+
assert.strictEqual(input.innerHTML.charCodeAt(0), 9825);
6767
}
6868
```
6969

70+
The `filled` class should contain style information.
71+
72+
```js
73+
const filled = new __helpers.CSSHelp(document).getStyle('.filled');
74+
assert.exists(filled);
75+
assert.isNotEmpty([...filled]);
76+
```
77+
7078
When the `button` element is clicked, and it contains the class `filled`, you should remove the class `filled` from the `button` element and change the innerHTML of the `button` element to `&#9825;`.
7179

7280
```js
@@ -76,10 +84,10 @@ assert.isNotEmpty(buttonElements);
7684
buttonElements.forEach(button => button.classList.add('filled'));
7785

7886
buttonElements.forEach(button => {
79-
button.dispatchEvent(new Event('click'));
80-
button.dispatchEvent(new Event('change'));
81-
assert.isFalse(button.classList.contains('filled'));
82-
assert.equal(button.innerHTML.charCodeAt(0), 9825);
87+
button.dispatchEvent(new Event('click'));
88+
button.dispatchEvent(new Event('change'));
89+
assert.isFalse(button.classList.contains('filled'));
90+
assert.equal(button.innerHTML.charCodeAt(0), 9825);
8391
});
8492
```
8593

@@ -92,10 +100,10 @@ assert.isNotEmpty(buttonElements);
92100
buttonElements.forEach(button => button.classList.remove('filled'));
93101

94102
buttonElements.forEach(button => {
95-
button.dispatchEvent(new Event('click'));
96-
button.dispatchEvent(new Event('change'));
97-
assert.isTrue(button.classList.contains('filled'));
98-
assert.equal(button.innerHTML.charCodeAt(0), 10084);
103+
button.dispatchEvent(new Event('click'));
104+
button.dispatchEvent(new Event('change'));
105+
assert.isTrue(button.classList.contains('filled'));
106+
assert.equal(button.innerHTML.charCodeAt(0), 10084);
99107
});
100108
```
101109

@@ -106,17 +114,15 @@ buttonElements.forEach(button => {
106114
```html
107115
<!DOCTYPE html>
108116
<html lang="en">
109-
110-
<head>
117+
<head>
111118
<meta charset="utf-8" />
112119
<title>Favorite Icon Toggler</title>
113120
<link rel="stylesheet" href="styles.css" />
114-
</head>
115-
116-
<body>
117-
118-
</body>
121+
</head>
119122

123+
<body>
124+
125+
</body>
120126
</html>
121127
```
122128

@@ -133,83 +139,81 @@ buttonElements.forEach(button => {
133139
```html
134140
<!DOCTYPE html>
135141
<html lang="en">
136-
137-
<head>
138-
<meta charset="UTF-8">
139-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
142+
<head>
143+
<meta charset="UTF-8" />
144+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
140145
<title>Favorite Icon Toggle</title>
141146
<link rel="stylesheet" href="styles.css" />
142-
</head>
147+
</head>
143148

144-
<body>
149+
<body>
145150
<h1>Art Supplies</h1>
146151
<ul class="item-list">
147-
<li>
148-
120 gm paper
149-
<button class="favorite-icon" id="favoriteIcon1">&#9825;</button>
150-
</li>
151-
<li>
152-
Watercolor set
153-
<button class="favorite-icon" id="favoriteIcon2">&#9825;</button>
154-
</li>
155-
<li>
156-
Lead pencil 6B
157-
<button class="favorite-icon" id="favoriteIcon3">&#9825;</button>
158-
</li>
152+
<li>
153+
120 gm paper
154+
<button class="favorite-icon" id="favoriteIcon1">&#9825;</button>
155+
</li>
156+
<li>
157+
Watercolor set
158+
<button class="favorite-icon" id="favoriteIcon2">&#9825;</button>
159+
</li>
160+
<li>
161+
Lead pencil 6B
162+
<button class="favorite-icon" id="favoriteIcon3">&#9825;</button>
163+
</li>
159164
</ul>
160165

161166
<script src="script.js"></script>
162-
</body>
163-
167+
</body>
164168
</html>
165169
```
166170

167171
```css
168172
body {
169-
display: flex;
170-
flex-direction: column;
171-
justify-content: center;
172-
align-items: center;
173-
height: 100vh;
174-
margin: 0;
175-
font-family: Arial, sans-serif;
173+
display: flex;
174+
flex-direction: column;
175+
justify-content: center;
176+
align-items: center;
177+
height: 100vh;
178+
margin: 0;
179+
font-family: Arial, sans-serif;
176180
}
177181

178182
h1 {
179-
margin-bottom: 20px;
183+
margin-bottom: 20px;
180184
}
181185

182186
.item-list {
183-
list-style-type: none;
184-
padding: 0;
187+
list-style-type: none;
188+
padding: 0;
185189
}
186190

187191
.item-list li {
188-
display: flex;
189-
justify-content: space-between;
190-
align-items: center;
191-
padding: 10px;
192-
border-bottom: 1px solid #ddd;
193-
width: 200px;
192+
display: flex;
193+
justify-content: space-between;
194+
align-items: center;
195+
padding: 10px;
196+
border-bottom: 1px solid #ddd;
197+
width: 200px;
194198
}
195199

196200
.favorite-icon {
197-
font-size: 1.25rem;
198-
background-color: transparent;
199-
border: none;
200-
cursor: pointer;
201+
font-size: 1.25rem;
202+
background-color: transparent;
203+
border: none;
204+
cursor: pointer;
201205
}
202206

203207
.filled {
204-
color: #D22B2B;
208+
color: #d22b2b;
205209
}
206210
```
207211

208212
```js
209213
document.addEventListener("DOMContentLoaded", () => {
210214
const favoriteIcons = document.querySelectorAll(".favorite-icon");
211215

212-
favoriteIcons.forEach((icon) => {
216+
favoriteIcons.forEach(icon => {
213217
icon.addEventListener("click", () => {
214218
if (icon.classList.contains("filled")) {
215219
icon.classList.remove("filled");

0 commit comments

Comments
 (0)