Add the class active and report the full class list.
Acceptance criteria
- 1.#out should show note active.
JavaScript Tutorial · JavaScript DOM
These 10 tasks go with the JavaScript classList 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: “classList adds, removes and toggles CSS classes on an element.” .
1.Add a classexercise · easy · 10 min
Add the class active and report the full class list.
Passes when: #out should show note active.
2.Remove a classexercise · easy · 10 min · practice plan
Remove the class one and report what is left.
Passes when: #out should show two.
3.Toggle a class onexercise · easy · 10 min · practice plan
Toggle the class open and report whether it is present.
Passes when: #out should show true.
4.Check for a classexercise · easy · 10 min · practice plan
Report whether the element has the class done.
Passes when: #out should show false.
5.Add several classesexercise · medium · 10 min · practice plan
Add three classes at once and report how many the element now has.
Passes when: #out should show 3.
6.Fix className wiping the other classesbug fix · easy · 8 min
Assigning to className replaces every class.
Passes when: #out should show keep added.
7.Fix the dot in the class namebug fix · easy · 8 min · practice plan
classList takes a bare name, without a dot.
Passes when: #out should show note active.
8.Fix the toggle called twicebug fix · easy · 8 min · practice plan
Toggling twice puts the class back where it started.
Passes when: #out should show true.
9.Fix contains used to addbug fix · easy · 8 min · practice plan
contains only checks; it does not change anything.
Passes when: #out should show has it.
10.Fix the wrong class removedbug fix · easy · 8 min · practice plan
The class that should stay is being taken off.
Passes when: #out should show two.
Between them these tasks cover classList, toggle and contains.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.