Build a small task tracker. Users type a task, add it to a list, and mark tasks as done, while the component keeps a live count of the remaining open tasks.
Render this exact structure:
- An
<input>element with the classnew-taskfor typing the task text. - A
<button>element with the classaddlabeledAdd. - A
<ul>element with the classtaskscontaining one<li>per task. Each<li>has the classtask(and additionally the classdonewhen the task is completed, so its class attribute becomestask done). Inside each<li>: a<span>with the classlabelholding the task text, and a<button>with the classcompletelabeledDone. - A
<p>element with the classremainingwhose text is exactlyRemaining: N, where N is the count of tasks that are not done. Initially the list is empty and the text isRemaining: 0.
Behavior:
- Typing in the input and clicking
Addappends a task with that text and clears the input. Blank or whitespace-only input must add nothing. - Clicking the
completebutton of a task marks that specific task as done: its<li>gains thedoneclass and the remaining count decreases. - Store tasks as objects with unique ids so each task can be identified. Remember that LWC only re-renders arrays when they are reassigned, and per-item CSS classes must be computed in a getter.
Examples:
Initial render:
<input class="new-task"> <button class="add">Add</button>
<ul class="tasks"></ul>
<p class="remaining">Remaining: 0</p>
Type "Write tests", click Add ->
<li class="task"><span class="label">Write tests</span><button class="complete">Done</button></li>
Remaining: 1
Click that task's Done button ->
<li class="task done"> ... </li>
Remaining: 0
Type " ", click Add -> nothing is added