@@ -9,73 +9,88 @@ dashedName: step-56
99
1010There's another way to associate an ` input ` element's text with the element itself. You can nest the text within a ` label ` element and add a ` for ` attribute with the same value as the ` input ` element's ` id ` attribute.
1111
12- Here is an example of using the ` for ` attribute to associate a ` label ` with an ` input ` element:
12+ Given an ` input ` element as below :
1313
1414``` html
15- <label for =" breakfast" > Breakfast </label >
1615<input id =" breakfast" type =" radio" name =" meal" value =" breakfast" >
1716```
1817
18+ An example of a ` label ` element that is associated to this ` input ` element is:
19+
20+ ``` html
21+ <label for =" breakfast" >Breakfast</label >
22+ ```
23+
1924Associate the text ` Loving ` with the checkbox by nesting only the text ` Loving ` in a ` label ` element and giving it an appropriate ` for ` attribute.
2025
2126# --hints--
2227
23- You should make sure the checkbox is still present.
28+ You should make sure the checkbox element is still present, and you did not make any changes to it. It should stay as it was in the starting code .
2429
2530``` js
26- assert ($ (' input[type="checkbox"]' )[0 ]);
31+ const checkboxElementRegex = / \s * <input\s + id\s * =\s * "loving"\s * type\s * =\s * "checkbox"\s * >/ ;
32+ assert .match (code, checkboxElementRegex);
2733```
2834
2935Your checkbox should still have an ` id ` attribute with the value ` loving ` . Expected ` --fcc-expected-- ` , but found ` --fcc-actual-- ` .
3036
3137``` js
32- assert .equal ($ (' input[type="checkbox"]' )[0 ].id , ' loving' );
38+ const checkboxElementId = document .querySelector (' input[type="checkbox"]' )? .getAttribute (' id' );
39+ assert .strictEqual (checkboxElementId, ' loving' );
3340` ` `
3441
35- The text ` Loving ` should be wrapped in a ` label ` element.
42+ You should add a new ` label` element after the checkbox element. Make sure it has both an opening and closing tag .
3643
3744` ` ` js
38- const checkboxInputElem = $ (' input[type="checkbox"]' )[0 ];
39- assert (
40- / Loving/ i .test (checkboxInputElem .nextElementSibling .innerText .replace (/ \s + / g , ' ' ))
41- );
45+ assert .lengthOf (document .querySelectorAll (' label' ), 3 );
46+ assert .lengthOf (code .match (/ <\/ label\> / g ), 3 );
4247` ` `
4348
44- You will need to add a new ` label ` element in which to nest the text ` Loving ` . Make sure it has both an opening and closing tag .
49+ Your ` label` element should be located after your checkbox .
4550
4651` ` ` js
47- assert (
48- document .querySelectorAll (' label' ).length === 3 &&
49- code .match (/ <\/ label\> / g ).length === 3
50- );
52+ const checkboxElement = document .querySelector (' input[type="checkbox"]' );
53+ const checkboxSiblingElement = checkboxElement? .nextElementSibling ? .nodeName ;
54+ assert .strictEqual (checkboxSiblingElement, ' LABEL' );
5155` ` `
5256
53- The new ` label ` element should be located directly to the right of your checkbox. Make sure there is a space between the two elements .
57+ Your ` label` element should have the text ` Loving ` .
5458
5559` ` ` js
56- const checkboxInputElem = $ (' input[type="checkbox"]' )[0 ];
57- assert (checkboxInputElem .nextElementSibling .nodeName === ' LABEL' );
60+ const checkboxElement = document .querySelector (' input[type="checkbox"]' );
61+ const checkboxSiblingElementText = checkboxElement? .nextElementSibling ? .innerText ;
62+
63+ assert .strictEqual (checkboxSiblingElementText, ' Loving' );
5864` ` `
5965
60- The new ` label ` element does not have a ` for ` attribute. Check that there is a space after the opening tag's name .
66+ The label text ` Loving ` should only be inside your new ` label ` element. Make sure you did not duplicate the text outside the ` label ` element .
6167
6268` ` ` js
63- const labelElem = $ (' input[type="checkbox"]' )[0 ].nextElementSibling ;
64- assert (labelElem .hasAttribute (' for' ));
69+ const checkboxElement = document .querySelector (' input[type="checkbox"]' );
70+ const checkboxSiblingNode = checkboxElement? .nextSibling ? .nodeValue ?? ' ' ;
71+ const labelElement = checkboxElement? .nextElementSibling ;
72+ const labelSiblingNode = labelElement? .nextSibling ? .nodeValue ?? ' ' ;
73+
74+ assert .notInclude (checkboxSiblingNode, ' Loving' );
75+ assert .notInclude (labelSiblingNode, ' Loving' );
6576` ` `
6677
67- The new ` label ` element should have a ` for ` attribute with the value ` loving ` . Expected ` --fcc-expected-- ` , but found ` --fcc-actual-- ` .
78+ Your ` label` element does not have a ` for ` attribute. Make sure there is a space between the opening ` label ` tag name and the ` for ` attribute .
6879
6980` ` ` js
70- const labelElem = $ (' input[type="checkbox"]' )[0 ].nextElementSibling ;
71- assert .equal (labelElem .getAttribute (' for' ), ' loving' );
81+ const checkboxElement = document .querySelector (' input[type="checkbox"]' );
82+ const checkboxSiblingElementAttr = checkboxElement? .nextElementSibling ? .getAttribute (' for' );
83+
84+ assert .isNotNull (checkboxSiblingElementAttr);
7285` ` `
7386
74- The text ` Loving ` should be nested within the new ` label ` element. You have either omitted the text or have a typo .
87+ Your ` label ` element should have a ` for ` attribute with the value ` loving ` . Expected ` -- fcc - expected -- ` , but found ` -- fcc - actual -- ` .
7588
7689` ` ` js
77- const labelElem = document .querySelector (' label[for="loving"]' );
78- assert (labelElem .textContent .replace (/ \s / g , ' ' ).match (/ Loving/ i ));
90+ const checkboxElement = document .querySelector (' input[type="checkbox"]' );
91+ const checkboxSiblingElementAttr = checkboxElement? .nextElementSibling ? .getAttribute (' for' );
92+
93+ assert .strictEqual (checkboxSiblingElementAttr, ' loving' );
7994` ` `
8095
8196There should be a space between your checkbox and your new ` label` element.
0 commit comments