Skip to content

Commit 9d9f65c

Browse files
fix(curriculum): implement updates to favorite icon toggler (freeCodeCamp#59492)
Co-authored-by: Jessica Wilkins <67210629+jdwilkin4@users.noreply.github.com>
1 parent 79d9798 commit 9d9f65c

1 file changed

Lines changed: 43 additions & 35 deletions

File tree

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

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@ demoType: onClick
1010

1111
In this lab you will use JavaScript click events to toggle the appearance of a favorite icon. When the heart icon is clicked, the appearance of the heart changes from empty to filled, and vice versa.
1212

13-
Fulfill the user stories below and get all the tests to pass to complete the lab. **Do not copy this demo project**.
13+
Fulfill the user stories below and get all the tests to pass to complete the lab.
1414

1515
**User Stories:**
1616

1717
1. You should have an unordered list with three items.
1818
2. The unordered list should have the class `item-list`.
19-
3. The three list items should contain the item name followed by a `span` element with the class `favorite-icon`.
20-
4. The `span` element should contain the code `&#9825;` initially to represent an empty heart.
21-
5. When a span element containing a heart is clicked, you should add the `filled` class to the clicked `span` if it's not already present, and remove it, if it is.
22-
6. When a `span` element containing a heart is clicked, the heart symbol should toggle between `&#9825;` (empty heart) and `&#10084;` (filled heart), depending on its current state.
19+
3. The three list items should contain the item name followed by a `button` element with the class `favorite-icon`.
20+
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.
23+
24+
**Note:** Be sure to link your JavaScript file in your HTML. (Ex. `<script src="script.js"></script>`)
2325

2426
# --hints--
2527

@@ -48,52 +50,52 @@ assert.exists(document.querySelector('ul li').textContent);
4850

4951
```
5052

51-
Your individual list item should contain a `span` element with the class `favorite-icon`
53+
Your individual list item should contain a `button` element with the class `favorite-icon`.
5254

5355
```js
54-
assert.exists(document.querySelector('ul li span.favorite-icon'));
56+
assert.exists(document.querySelector('ul li button.favorite-icon'));
5557
```
5658

57-
Initially, the `span` elements should contain the code `&#9825;` to represent an empty heart.
59+
Initially, the `button` elements should contain the code `&#9825;` to represent an empty heart.
5860

5961
```js
60-
const inputs = document.querySelectorAll('ul li span.favorite-icon');
62+
const inputs = document.querySelectorAll('ul li button.favorite-icon');
6163
assert.isNotEmpty(inputs)
6264

6365
for (let input of inputs) {
6466
assert.strictEqual(input.innerHTML.charCodeAt(0), 9825);
6567
}
6668
```
6769

68-
When the `span` element is clicked, and it contains the class `filled`, you should remove the class `filled` from the `span` element and change the innerHTML of the `span` element to `&#9825;`.
70+
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;`.
6971

7072
```js
71-
const spanElements = document.querySelectorAll('.favorite-icon');
72-
assert.isNotEmpty(spanElements);
73+
const buttonElements = document.querySelectorAll('.favorite-icon');
74+
assert.isNotEmpty(buttonElements);
7375

74-
spanElements.forEach(span => span.classList.add('filled'));
76+
buttonElements.forEach(button => button.classList.add('filled'));
7577

76-
spanElements.forEach(span => {
77-
span.dispatchEvent(new Event('click'));
78-
span.dispatchEvent(new Event('change'));
79-
assert.isFalse(span.classList.contains('filled'));
80-
assert.equal(span.innerHTML.charCodeAt(0), 9825);
78+
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);
8183
});
8284
```
8385

84-
When the `span` element is clicked, and it doesn't contain the class `filled`, you should add the class `filled` to the `span` element and change the `innerHTML` of the `span` element to `&#10084;`.
86+
When the `button` element is clicked, and it doesn't contain the class `filled`, you should add the class `filled` to the `button` element and change the `innerHTML` of the `button` element to `&#10084;`.
8587

8688
```js
87-
const spanElements = document.querySelectorAll('.favorite-icon');
88-
assert.isNotEmpty(spanElements);
89+
const buttonElements = document.querySelectorAll('.favorite-icon');
90+
assert.isNotEmpty(buttonElements);
8991

90-
spanElements.forEach(span => span.classList.remove('filled'));
92+
buttonElements.forEach(button => button.classList.remove('filled'));
9193

92-
spanElements.forEach(span => {
93-
span.dispatchEvent(new Event('click'));
94-
span.dispatchEvent(new Event('change'));
95-
assert.isTrue(span.classList.contains('filled'));
96-
assert.equal(span.innerHTML.charCodeAt(0), 10084);
94+
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);
9799
});
98100
```
99101

@@ -106,9 +108,9 @@ spanElements.forEach(span => {
106108
<html lang="en">
107109

108110
<head>
109-
<meta charset="utf-8">
110-
<title></title>
111-
<link rel="stylesheet" href="styles.css">
111+
<meta charset="utf-8" />
112+
<title>Favorite Icon Toggler</title>
113+
<link rel="stylesheet" href="styles.css" />
112114
</head>
113115

114116
<body>
@@ -136,23 +138,23 @@ spanElements.forEach(span => {
136138
<meta charset="UTF-8">
137139
<meta name="viewport" content="width=device-width, initial-scale=1.0">
138140
<title>Favorite Icon Toggle</title>
139-
<link rel="stylesheet" href="styles.css">
141+
<link rel="stylesheet" href="styles.css" />
140142
</head>
141143

142144
<body>
143145
<h1>Art Supplies</h1>
144146
<ul class="item-list">
145147
<li>
146148
120 gm paper
147-
<span class="favorite-icon" id="favoriteIcon1">&#9825;</span>
149+
<button class="favorite-icon" id="favoriteIcon1">&#9825;</button>
148150
</li>
149151
<li>
150152
Watercolor set
151-
<span class="favorite-icon" id="favoriteIcon2">&#9825;</span>
153+
<button class="favorite-icon" id="favoriteIcon2">&#9825;</button>
152154
</li>
153155
<li>
154156
Lead pencil 6B
155-
<span class="favorite-icon" id="favoriteIcon3">&#9825;</span>
157+
<button class="favorite-icon" id="favoriteIcon3">&#9825;</button>
156158
</li>
157159
</ul>
158160

@@ -192,9 +194,15 @@ h1 {
192194
}
193195

194196
.favorite-icon {
195-
font-size: 20px;
197+
font-size: 1.25rem;
198+
background-color: transparent;
199+
border: none;
196200
cursor: pointer;
197201
}
202+
203+
.filled {
204+
color: #D22B2B;
205+
}
198206
```
199207

200208
```js

0 commit comments

Comments
 (0)