Report the href of the link.
Acceptance criteria
- 1.#out should show /about.
JavaScript Tutorial · JavaScript DOM
These 10 tasks go with the JavaScript DOM Attributes chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “JavaScript reads and changes HTML attributes with getAttribute, setAttribute and dataset.” .
1.Read an attributeexercise · easy · 10 min
Report the href of the link.
Passes when: #out should show /about.
2.Change an attributeexercise · easy · 10 min · practice plan
Change the alt text to Updated and report it back.
Passes when: #out should show Updated.
3.Read a data attributeexercise · easy · 10 min · practice plan
Report the value of data-user-id using dataset.
Passes when: #out should show 42.
4.Remove an attributeexercise · easy · 10 min · practice plan
Remove the disabled attribute and report whether it is still there.
Passes when: #out should show false.
5.Read a class as a propertyexercise · medium · 10 min · practice plan
Report the class of the link using its property, not getAttribute.
Passes when: #out should show nav.
6.Fix the dot used for a data attributebug fix · easy · 8 min
A data attribute is not a plain property of the element.
Passes when: #out should show 42.
7.Fix the dashed dataset namebug fix · easy · 8 min · practice plan
dataset uses camel case, not the dashed attribute name.
Passes when: #out should show docs.
8.Fix setAttribute given one argumentbug fix · easy · 8 min · practice plan
setAttribute needs both a name and a value.
Passes when: #out should show Updated.
9.Fix class read as a property namebug fix · easy · 8 min · practice plan
The property is called className, because class is reserved.
Passes when: #out should show nav.
10.Fix the attribute checked instead of the propertybug fix · easy · 8 min · practice plan
A checkbox ticked in code changes the property, not the attribute.
Passes when: #out should show true.
Between them these tasks cover getAttribute, setAttribute and dataset.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.