Skip to content

Commit 8c0f9bf

Browse files
feat(curriculum): add debug donation form lab (freeCodeCamp#63632)
Co-authored-by: Ilenia <[email protected]> Co-authored-by: majestic-owl448 <[email protected]>
1 parent 7d58ef2 commit 8c0f9bf

File tree

5 files changed

+217
-0
lines changed

5 files changed

+217
-0
lines changed

client/i18n/locales/english/intro.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8024,6 +8024,12 @@
80248024
"In this workshop, you will build an accessible tech conference schedule table."
80258025
]
80268026
},
8027+
"lab-debug-donation-form": {
8028+
"title": "Debug a Donation Form",
8029+
"intro": [
8030+
"In this lab you will debug a donation form by fixing HTML syntax errors and improving accessibility."
8031+
]
8032+
},
80278033
"lecture-introduction-to-aria": {
80288034
"title": "Introduction to ARIA",
80298035
"intro": [
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: Introduction to the Debug a Donation Form
3+
block: lab-debug-donation-form
4+
superBlock: responsive-web-design-v9
5+
---
6+
7+
## Introduction to the Debug a Donation Form
8+
9+
In this lab you will debug a donation form by fixing HTML syntax errors and improving accessibility.
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
---
2+
id: 690ddb5e6ee94eb73ed172b0
3+
title: Debug a Donation Form
4+
challengeType: 25
5+
dashedName: debug-donation-form
6+
# Purposefully removed the demo type because this is a debugging project.
7+
---
8+
9+
# --description--
10+
11+
A local charity has built a donation form website, but there are several issues that need to be fixed. The form isn't accessible and has some HTML syntax errors.
12+
13+
Your job is to fix all of the errors so the form works correctly and is accessible to all users. Complete the items in the user stories below and click "Run the Tests" to see if you fixed all the errors.
14+
15+
**User Stories:**
16+
17+
1. The `input` elements are void elements and should not have closing tags. Remove all `</input>` closing tags from the form.
18+
2. Add `label` elements for each form input field so users know what each field is for. The label text should match what's currently next to each input.
19+
3. The `Email Address:` input type should be an `email` instead of `text`.
20+
4. You should associate each `label` element with its corresponding `input` element using the `for` attribute on the `label` and a matching `id` attribute on the `input`.
21+
5. Add the `required` attribute to the text, email, and number input fields (but not the checkbox or submit button) to ensure users fill in the required information.
22+
23+
# --hints--
24+
25+
You should not have any `</input>` closing tags in your code.
26+
27+
```js
28+
assert.notMatch(code, /<\/input>/);
29+
```
30+
31+
You should have exactly five `input` elements in your form.
32+
33+
```js
34+
assert.lengthOf(document.querySelectorAll("input"), 5);
35+
```
36+
37+
You should have exactly four `label` elements in your form.
38+
39+
```js
40+
assert.lengthOf(document.querySelectorAll("label"), 4);
41+
```
42+
43+
Your first `label` should have the text `Full Name:`.
44+
45+
```js
46+
const labels = document.querySelectorAll("label");
47+
assert.match(labels[0]?.textContent, /Full\s*Name\s*:/i);
48+
```
49+
50+
Your first `input` should have a `required` attribute.
51+
52+
```js
53+
const firstInput = document.querySelector("input[name='name']");
54+
assert.isTrue(firstInput?.hasAttribute("required"));
55+
```
56+
57+
Your second `label` should have the text `Email Address:`.
58+
59+
```js
60+
const labels = document.querySelectorAll("label");
61+
assert.match(labels[1]?.textContent, /Email\s*Address\s*:/i);
62+
```
63+
64+
Your second `input` should have a `required` attribute.
65+
66+
```js
67+
const secondInput = document.querySelector("input[name='email']");
68+
assert.isTrue(secondInput?.hasAttribute("required"));
69+
```
70+
71+
Your third `label` should have the text `Donation Amount ($):`.
72+
73+
```js
74+
const labels = document.querySelectorAll("label");
75+
assert.match(labels[2]?.textContent, /Donation\s*Amount\s*\(\$\)\s*:/i);
76+
```
77+
78+
Your third `input` should have a`required` attribute.
79+
80+
```js
81+
const thirdInput = document.querySelector("input[name='amount']");
82+
assert.isTrue(thirdInput?.hasAttribute("required"));
83+
```
84+
85+
Your fourth `label` should have the text `Subscribe`.
86+
87+
```js
88+
const labels = document.querySelectorAll("label");
89+
assert.match(labels[3]?.textContent, /Subscribe/i);
90+
```
91+
92+
You should associate every `input` element with a `label` element using the `for` and `id` attributes.
93+
94+
```js
95+
const els = document.querySelectorAll('input:not([type="submit"])');
96+
assert.isNotEmpty(els);
97+
els.forEach(input => {
98+
const label = document.querySelector(`label[for="${input.id}"]`);
99+
assert.exists(label);
100+
assert.equal(label.tagName, "LABEL");
101+
})
102+
```
103+
104+
Your `input` for the email address should be of type `email`.
105+
106+
```js
107+
const emailInput = document.querySelector("input[name='email']");
108+
assert.strictEqual(emailInput?.getAttribute("type"), "email");
109+
```
110+
111+
Your checkbox `input` should not have a `required` attribute.
112+
113+
```js
114+
const checkboxInput = document.querySelector("input[name='newsletter']");
115+
assert.isFalse(checkboxInput?.hasAttribute("required"));
116+
```
117+
118+
Your submit `button` should not have a `required` attribute.
119+
120+
```js
121+
const submitButton = document.querySelector("input[type='submit']");
122+
assert.isFalse(submitButton?.hasAttribute("required"));
123+
```
124+
125+
# --seed--
126+
127+
## --seed-contents--
128+
129+
```html
130+
<!DOCTYPE html>
131+
<html lang="en">
132+
<head>
133+
<meta charset="UTF-8">
134+
<title>Donation Form</title>
135+
</head>
136+
<body>
137+
<h1>Donation Form</h1>
138+
<form>
139+
140+
Full Name:
141+
<input type="text" name="name"></input>
142+
143+
Email Address:
144+
<input type="text" name="email">
145+
146+
Donation Amount ($):
147+
<input type="number" name="amount"></input>
148+
149+
<input type="checkbox" name="newsletter"></input>
150+
Subscribe
151+
152+
<input type="submit" value="Send"></input>
153+
</form>
154+
</body>
155+
</html>
156+
```
157+
158+
# --solutions--
159+
160+
```html
161+
<!DOCTYPE html>
162+
<html lang="en">
163+
<head>
164+
<meta charset="UTF-8">
165+
<title>Donation Form</title>
166+
</head>
167+
<body>
168+
<h1>Donation Form</h1>
169+
<form>
170+
<label for="full-name">Full Name:</label>
171+
<input id="full-name" type="text" name="name" required>
172+
173+
<label for="email">Email Address:</label>
174+
<input id="email" type="email" name="email" required>
175+
176+
<label for="amount">Donation Amount ($):</label>
177+
<input id="amount" type="number" name="amount" required>
178+
179+
<label for="newsletter">Subscribe</label>
180+
<input id="newsletter" type="checkbox" name="newsletter">
181+
182+
<input type="submit" value="Send">
183+
</form>
184+
</body>
185+
</html>
186+
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "Debug a Donation Form",
3+
"isUpcomingChange": false,
4+
"dashedName": "lab-debug-donation-form",
5+
"helpCategory": "HTML-CSS",
6+
"blockLayout": "link",
7+
"challengeOrder": [
8+
{
9+
"id": "690ddb5e6ee94eb73ed172b0",
10+
"title": "Debug a Donation Form"
11+
}
12+
],
13+
"blockLabel": "lab",
14+
"usesMultifileEditor": true
15+
}

curriculum/structure/superblocks/responsive-web-design-v9.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"workshop-debug-coding-journey-blog-page",
7171
"lecture-accessible-tables-forms",
7272
"workshop-tech-conference-schedule",
73+
"lab-debug-donation-form",
7374
"lecture-introduction-to-aria",
7475
"workshop-accessible-audio-controller",
7576
"lecture-accessible-media-elements",

0 commit comments

Comments
 (0)