JavaScript DOM Attributes — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript DOM Attributes lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.
Exercises(5)
- 1
Read an attribute
easy10 minReport the href of the link.
- 2
Change an attribute
easy10 minChange the alt text to Updated and report it back.
- 3
Read a data attribute
easy10 minReport the value of data-user-id using dataset.
- 4
Remove an attribute
easy10 minRemove the disabled attribute and report whether it is still there.
- 5
Read a class as a property
medium10 minReport the class of the link using its property, not getAttribute.
Find the bug(5)
- 1
Fix the dot used for a data attribute
easy8 minA data attribute is not a plain property of the element.
- 2
Fix the dashed dataset name
easy8 mindataset uses camel case, not the dashed attribute name.
- 3
Fix setAttribute given one argument
easy8 minsetAttribute needs both a name and a value.
- 4
Fix class read as a property name
easy8 minThe property is called className, because class is reserved.
- 5
Fix the attribute checked instead of the property
easy8 minA checkbox ticked in code changes the property, not the attribute.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace