From Zero to Senior · The LabالعربيةGitHub

Chapter 17

Project: Build and Publish a Web App

2 examples · 3 projects · 5 exercises

In this chapter you will

  • plan an app before writing code: features, a sketch and the shape of the data
  • build a complete daily tasks app with HTML, CSS and JavaScript
  • save data in the browser with localStorage, so it survives a reload
  • test it like a professional: keyboard, phone width and unusual cases
  • publish it on the internet for free with GitHub Pages

Examples

17.2 The HTML

Create a folder called my-tasks with three files. The HTML holds the structure, and is almost empty where the tasks will go:

index.html↗ Open page⤓ File
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>My Tasks</title>
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    <main class="app">
      <h1>My Tasks</h1>
      <p class="subtitle">Small steps, every day.</p>

      <form id="new-task">
        <label for="task-text" class="visually-hidden">New task</label>
        <input id="task-text" type="text" placeholder="e.g. Read chapter 17" required>
        <button class="primary" type="submit">Add</button>
      </form>

      <div class="filters" role="group" aria-label="Show">
        <button type="button" data-filter="all" aria-pressed="true">All</button>
        <button type="button" data-filter="active" aria-pressed="false">To do</button>
        <button type="button" data-filter="done" aria-pressed="false">Done</button>
      </div>

      <ul id="tasks"></ul>
      <p class="empty" id="empty">Nothing here yet. Add your first task above!</p>

      <footer>
        <span id="count" aria-live="polite"></span>
        <button type="button" id="clear">Clear done</button>
      </footer>
    </main>
    <script src="app.js"></script>
  </body>
</html>
index.html560px
Figure 17.2: The finished app with three tasks, one of them done.

17.4 The JavaScript

The program follows the pattern from Chapter 12: data, changes, display, and events. Read it section by section:

app.js⤓ File
// ---------- Data ----------
const STORAGE_KEY = "my-tasks";
let tasks = load();
let filter = "all";

function load() {
  const saved = localStorage.getItem(STORAGE_KEY);
  return saved ? JSON.parse(saved) : [];
}

function save() {
  localStorage.setItem(STORAGE_KEY, JSON.stringify(tasks));
}

// ---------- Changes ----------
function addTask(text) {
  tasks.push({ id: Date.now(), text, done: false });
  update();
}

function toggleTask(id) {
  const task = tasks.find((t) => t.id === id);
  task.done = !task.done;
  update();
}

function deleteTask(id) {
  tasks = tasks.filter((t) => t.id !== id);
  update();
}

function clearDone() {
  tasks = tasks.filter((t) => !t.done);
  update();
}

function update() {
  save();
  render();
}

// ---------- Display ----------
function visibleTasks() {
  if (filter === "active") return tasks.filter((t) => !t.done);
  if (filter === "done") return tasks.filter((t) => t.done);
  return tasks;
}

function taskItem(task) {
  const li = document.createElement("li");
  li.classList.toggle("done", task.done);

  const box = document.createElement("input");
  box.type = "checkbox";
  box.id = `task-${task.id}`;
  box.checked = task.done;
  box.addEventListener("change", () => toggleTask(task.id));

  const label = document.createElement("label");
  label.htmlFor = box.id;
  label.textContent = task.text;

  const remove = document.createElement("button");
  remove.type = "button";
  remove.className = "delete";
  remove.textContent = "Delete";
  remove.setAttribute("aria-label", `Delete: ${task.text}`);
  remove.addEventListener("click", () => deleteTask(task.id));

  li.append(box, label, remove);
  return li;
}

function leftText(count) {
  if (count === 0) return "All done!";
  if (count === 1) return "1 task left";
  return `${count} tasks left`;
}

function render() {
  const list = document.querySelector("#tasks");
  list.replaceChildren(...visibleTasks().map(taskItem));

  document.querySelector("#empty").hidden = tasks.length > 0;

  const count = tasks.filter((t) => !t.done).length;
  document.querySelector("#count").textContent = leftText(count);

  for (const button of document.querySelectorAll("[data-filter]")) {
    button.setAttribute("aria-pressed", String(button.dataset.filter === filter));
  }
}

// ---------- Events ----------
document.querySelector("#new-task").addEventListener("submit", (event) => {
  event.preventDefault();
  const input = document.querySelector("#task-text");
  const text = input.value.trim();
  if (text) {
    addTask(text);
    input.value = "";
  }
  input.focus();
});

for (const button of document.querySelectorAll("[data-filter]")) {
  button.addEventListener("click", () => {
    filter = button.dataset.filter;
    render();
  });
}

document.querySelector("#clear").addEventListener("click", clearDone);

render();
+ 1 files
style.css⤓ File
*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --brand: #4338ca;
  --accent: #db2777;
  --ink: #1e1b2e;
  --muted: #5b5873;
  --soft: #eef2ff;
}

body {
  margin: 0;
  font-family: system-ui, "Segoe UI", Tahoma, sans-serif;
  color: var(--ink);
  background: var(--soft);
}

.app {
  max-width: 560px;
  margin: 32px auto;
  padding: 24px;
  background: white;
  border-radius: 20px;
  box-shadow: 0 4px 20px rgba(30, 27, 46, 0.1);
}

h1 {
  margin: 0;
  color: var(--brand);
}

.subtitle {
  margin: 4px 0 20px;
  color: var(--muted);
}

form {
  display: flex;
  gap: 8px;
}

form input {
  flex: 1;
  padding: 10px 14px;
  font: inherit;
  border: 2px solid #c7c5dd;
  border-radius: 12px;
}

button {
  font: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 999px;
}

.primary {
  padding: 10px 20px;
  color: white;
  background: var(--brand);
}

.filters {
  display: flex;
  gap: 6px;
  margin: 18px 0 8px;
}

.filters button {
  padding: 6px 14px;
  color: var(--brand);
  background: var(--soft);
}

.filters button[aria-pressed="true"] {
  color: white;
  background: var(--brand);
}

ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--soft);
}

li label {
  flex: 1;
}

li.done label {
  color: var(--muted);
  text-decoration: line-through;
}

li input {
  width: 20px;
  height: 20px;
  accent-color: var(--brand);
}

.delete {
  padding: 4px 12px;
  color: var(--accent);
  background: #fdf0f6;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 24px 0;
}

footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  color: var(--muted);
}

footer button {
  padding: 4px 10px;
  color: var(--muted);
  background: none;
  text-decoration: underline;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

Practice projects

Project 17.1 · Easy

A progress bar

Show how much of the list is done, as a bar and in words, and keep it in step with every change.

You will practise: the <progress> element, adding to render(), and accent-color.

Steps
  1. In the HTML, above the list, add <progress id="progress" max="1" value="0"> and a <span id="progress-text">. Link them with aria-labelledby so the bar has a name.
  2. In the CSS, let the bar fill the row with flex: 1, and colour it with accent-color: var(--brand).
  3. In render(), work out done = tasks.length - count, then set the bar’s max and value.
  4. Use tasks.length || 1 for max, so an empty list does not divide by zero.
  5. Write “1 of 3 done” into the span. Tick, untick, add and delete tasks, and check that the bar is always right.

Hint: you did not touch addTask, toggleTask or deleteTask. Because every change ends in render(), one new block there is enough. That is the reward for the structure you built in this chapter.

Solution
progress/index.html↗ Open page⤓ File
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>My Tasks</title>
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    <main class="app">
      <h1>My Tasks</h1>
      <p class="subtitle">Small steps, every day.</p>

      <form id="new-task">
        <label for="task-text" class="visually-hidden">New task</label>
        <input id="task-text" type="text" placeholder="e.g. Read chapter 17" required>
        <button class="primary" type="submit">Add</button>
      </form>

      <div class="filters" role="group" aria-label="Show">
        <button type="button" data-filter="all" aria-pressed="true">All</button>
        <button type="button" data-filter="active" aria-pressed="false">To do</button>
        <button type="button" data-filter="done" aria-pressed="false">Done</button>
      </div>

      <div class="progress">
        <progress id="progress" max="1" value="0" aria-labelledby="progress-text"></progress>
        <span id="progress-text"></span>
      </div>

      <ul id="tasks"></ul>
      <p class="empty" id="empty">Nothing here yet. Add your first task above!</p>

      <footer>
        <span id="count" aria-live="polite"></span>
        <button type="button" id="clear">Clear done</button>
      </footer>
    </main>
    <script src="app.js"></script>
  </body>
</html>
index.html560px
Project 17.1: one of three tasks done.
progress/app.js⤓ File
// ---------- Data ----------
const STORAGE_KEY = "my-tasks";
let tasks = load();
let filter = "all";

function load() {
  const saved = localStorage.getItem(STORAGE_KEY);
  return saved ? JSON.parse(saved) : [];
}

function save() {
  localStorage.setItem(STORAGE_KEY, JSON.stringify(tasks));
}

// ---------- Changes ----------
function addTask(text) {
  tasks.push({ id: Date.now(), text, done: false });
  update();
}

function toggleTask(id) {
  const task = tasks.find((t) => t.id === id);
  task.done = !task.done;
  update();
}

function deleteTask(id) {
  tasks = tasks.filter((t) => t.id !== id);
  update();
}

function clearDone() {
  tasks = tasks.filter((t) => !t.done);
  update();
}

function update() {
  save();
  render();
}

// ---------- Display ----------
function visibleTasks() {
  if (filter === "active") return tasks.filter((t) => !t.done);
  if (filter === "done") return tasks.filter((t) => t.done);
  return tasks;
}

function taskItem(task) {
  const li = document.createElement("li");
  li.classList.toggle("done", task.done);

  const box = document.createElement("input");
  box.type = "checkbox";
  box.id = `task-${task.id}`;
  box.checked = task.done;
  box.addEventListener("change", () => toggleTask(task.id));

  const label = document.createElement("label");
  label.htmlFor = box.id;
  label.textContent = task.text;

  const remove = document.createElement("button");
  remove.type = "button";
  remove.className = "delete";
  remove.textContent = "Delete";
  remove.setAttribute("aria-label", `Delete: ${task.text}`);
  remove.addEventListener("click", () => deleteTask(task.id));

  li.append(box, label, remove);
  return li;
}

function leftText(count) {
  if (count === 0) return "All done!";
  if (count === 1) return "1 task left";
  return `${count} tasks left`;
}

function render() {
  const list = document.querySelector("#tasks");
  list.replaceChildren(...visibleTasks().map(taskItem));

  document.querySelector("#empty").hidden = tasks.length > 0;

  const count = tasks.filter((t) => !t.done).length;
  document.querySelector("#count").textContent = leftText(count);

  const done = tasks.length - count;
  const bar = document.querySelector("#progress");
  bar.max = tasks.length || 1;
  bar.value = done;
  document.querySelector("#progress-text").textContent = `${done} of ${tasks.length} done`;

  for (const button of document.querySelectorAll("[data-filter]")) {
    button.setAttribute("aria-pressed", String(button.dataset.filter === filter));
  }
}

// ---------- Events ----------
document.querySelector("#new-task").addEventListener("submit", (event) => {
  event.preventDefault();
  const input = document.querySelector("#task-text");
  const text = input.value.trim();
  if (text) {
    addTask(text);
    input.value = "";
  }
  input.focus();
});

for (const button of document.querySelectorAll("[data-filter]")) {
  button.addEventListener("click", () => {
    filter = button.dataset.filter;
    render();
  });
}

document.querySelector("#clear").addEventListener("click", clearDone);

render();
progress/style.css⤓ File
*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --brand: #4338ca;
  --accent: #db2777;
  --ink: #1e1b2e;
  --muted: #5b5873;
  --soft: #eef2ff;
}

body {
  margin: 0;
  font-family: system-ui, "Segoe UI", Tahoma, sans-serif;
  color: var(--ink);
  background: var(--soft);
}

.app {
  max-width: 560px;
  margin: 32px auto;
  padding: 24px;
  background: white;
  border-radius: 20px;
  box-shadow: 0 4px 20px rgba(30, 27, 46, 0.1);
}

h1 {
  margin: 0;
  color: var(--brand);
}

.subtitle {
  margin: 4px 0 20px;
  color: var(--muted);
}

form {
  display: flex;
  gap: 8px;
}

form input {
  flex: 1;
  padding: 10px 14px;
  font: inherit;
  border: 2px solid #c7c5dd;
  border-radius: 12px;
}

button {
  font: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 999px;
}

.primary {
  padding: 10px 20px;
  color: white;
  background: var(--brand);
}

.filters {
  display: flex;
  gap: 6px;
  margin: 18px 0 8px;
}

.filters button {
  padding: 6px 14px;
  color: var(--brand);
  background: var(--soft);
}

.filters button[aria-pressed="true"] {
  color: white;
  background: var(--brand);
}

ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--soft);
}

li label {
  flex: 1;
}

li.done label {
  color: var(--muted);
  text-decoration: line-through;
}

li input {
  width: 20px;
  height: 20px;
  accent-color: var(--brand);
}

.delete {
  padding: 4px 12px;
  color: var(--accent);
  background: #fdf0f6;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 24px 0;
}

footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  color: var(--muted);
}

footer button {
  padding: 4px 10px;
  color: var(--muted);
  background: none;
  text-decoration: underline;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

.progress progress {
  flex: 1;
  height: 10px;
  accent-color: var(--brand);
}

Project 17.2 · Medium

Edit a task

Typos happen. Let the user fix a task’s text in place: Enter saves, Escape cancels.

You will practise: a new change function, replaceWith, keyboard events, focus() and select().

Steps
  1. Add renameTask(id, text) next to the other change functions: find the task, change its text, and call update().
  2. In taskItem, add an “Edit” button with an aria-label that names the task, like the delete button.
  3. Write startEditing(li, task): create an input holding the current text, and swap it in with label.replaceWith(input). Then call focus() and select().
  4. Listen for keydown on the input. On "Enter", save the trimmed text if it is not empty. On "Escape", just call render().
  5. When the input loses focus (blur), call render() too, so a half-edited task never stays on screen.

Hint: section 17.7 suggested double-clicking. A button is better: double-click cannot be done with a keyboard or easily on a phone, and you learned in chapter 16 why that matters.

Solution
edit/index.html↗ Open page⤓ File
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>My Tasks</title>
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    <main class="app">
      <h1>My Tasks</h1>
      <p class="subtitle">Small steps, every day.</p>

      <form id="new-task">
        <label for="task-text" class="visually-hidden">New task</label>
        <input id="task-text" type="text" placeholder="e.g. Read chapter 17" required>
        <button class="primary" type="submit">Add</button>
      </form>

      <div class="filters" role="group" aria-label="Show">
        <button type="button" data-filter="all" aria-pressed="true">All</button>
        <button type="button" data-filter="active" aria-pressed="false">To do</button>
        <button type="button" data-filter="done" aria-pressed="false">Done</button>
      </div>

      <ul id="tasks"></ul>
      <p class="empty" id="empty">Nothing here yet. Add your first task above!</p>

      <footer>
        <span id="count" aria-live="polite"></span>
        <button type="button" id="clear">Clear done</button>
      </footer>
    </main>
    <script src="app.js"></script>
  </body>
</html>
index.html560px
Project 17.2: editing the second task.
edit/app.js⤓ File
// ---------- Data ----------
const STORAGE_KEY = "my-tasks";
let tasks = load();
let filter = "all";

function load() {
  const saved = localStorage.getItem(STORAGE_KEY);
  return saved ? JSON.parse(saved) : [];
}

function save() {
  localStorage.setItem(STORAGE_KEY, JSON.stringify(tasks));
}

// ---------- Changes ----------
function addTask(text) {
  tasks.push({ id: Date.now(), text, done: false });
  update();
}

function toggleTask(id) {
  const task = tasks.find((t) => t.id === id);
  task.done = !task.done;
  update();
}

function renameTask(id, text) {
  const task = tasks.find((t) => t.id === id);
  task.text = text;
  update();
}

function deleteTask(id) {
  tasks = tasks.filter((t) => t.id !== id);
  update();
}

function clearDone() {
  tasks = tasks.filter((t) => !t.done);
  update();
}

function update() {
  save();
  render();
}

// ---------- Display ----------
function visibleTasks() {
  if (filter === "active") return tasks.filter((t) => !t.done);
  if (filter === "done") return tasks.filter((t) => t.done);
  return tasks;
}

function taskItem(task) {
  const li = document.createElement("li");
  li.classList.toggle("done", task.done);

  const box = document.createElement("input");
  box.type = "checkbox";
  box.id = `task-${task.id}`;
  box.checked = task.done;
  box.addEventListener("change", () => toggleTask(task.id));

  const label = document.createElement("label");
  label.htmlFor = box.id;
  label.textContent = task.text;

  const remove = document.createElement("button");
  remove.type = "button";
  remove.className = "delete";
  remove.textContent = "Delete";
  remove.setAttribute("aria-label", `Delete: ${task.text}`);
  remove.addEventListener("click", () => deleteTask(task.id));

  const edit = document.createElement("button");
  edit.type = "button";
  edit.className = "edit";
  edit.textContent = "Edit";
  edit.setAttribute("aria-label", `Edit: ${task.text}`);
  edit.addEventListener("click", () => startEditing(li, task));

  li.append(box, label, edit, remove);
  return li;
}

function startEditing(li, task) {
  const input = document.createElement("input");
  input.className = "edit-text";
  input.value = task.text;
  input.setAttribute("aria-label", "Edit task");

  input.addEventListener("keydown", (event) => {
    if (event.key === "Enter") {
      const text = input.value.trim();
      if (text) renameTask(task.id, text);
      else render();
    }
    if (event.key === "Escape") render();
  });
  input.addEventListener("blur", () => render());

  li.querySelector("label").replaceWith(input);
  input.focus();
  input.select();
}

function leftText(count) {
  if (count === 0) return "All done!";
  if (count === 1) return "1 task left";
  return `${count} tasks left`;
}

function render() {
  const list = document.querySelector("#tasks");
  list.replaceChildren(...visibleTasks().map(taskItem));

  document.querySelector("#empty").hidden = tasks.length > 0;

  const count = tasks.filter((t) => !t.done).length;
  document.querySelector("#count").textContent = leftText(count);

  for (const button of document.querySelectorAll("[data-filter]")) {
    button.setAttribute("aria-pressed", String(button.dataset.filter === filter));
  }
}

// ---------- Events ----------
document.querySelector("#new-task").addEventListener("submit", (event) => {
  event.preventDefault();
  const input = document.querySelector("#task-text");
  const text = input.value.trim();
  if (text) {
    addTask(text);
    input.value = "";
  }
  input.focus();
});

for (const button of document.querySelectorAll("[data-filter]")) {
  button.addEventListener("click", () => {
    filter = button.dataset.filter;
    render();
  });
}

document.querySelector("#clear").addEventListener("click", clearDone);

render();
edit/style.css⤓ File
*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --brand: #4338ca;
  --accent: #db2777;
  --ink: #1e1b2e;
  --muted: #5b5873;
  --soft: #eef2ff;
}

body {
  margin: 0;
  font-family: system-ui, "Segoe UI", Tahoma, sans-serif;
  color: var(--ink);
  background: var(--soft);
}

.app {
  max-width: 560px;
  margin: 32px auto;
  padding: 24px;
  background: white;
  border-radius: 20px;
  box-shadow: 0 4px 20px rgba(30, 27, 46, 0.1);
}

h1 {
  margin: 0;
  color: var(--brand);
}

.subtitle {
  margin: 4px 0 20px;
  color: var(--muted);
}

form {
  display: flex;
  gap: 8px;
}

form input {
  flex: 1;
  padding: 10px 14px;
  font: inherit;
  border: 2px solid #c7c5dd;
  border-radius: 12px;
}

button {
  font: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 999px;
}

.primary {
  padding: 10px 20px;
  color: white;
  background: var(--brand);
}

.filters {
  display: flex;
  gap: 6px;
  margin: 18px 0 8px;
}

.filters button {
  padding: 6px 14px;
  color: var(--brand);
  background: var(--soft);
}

.filters button[aria-pressed="true"] {
  color: white;
  background: var(--brand);
}

ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--soft);
}

li label {
  flex: 1;
}

li.done label {
  color: var(--muted);
  text-decoration: line-through;
}

li input {
  width: 20px;
  height: 20px;
  accent-color: var(--brand);
}

.delete {
  padding: 4px 12px;
  color: var(--accent);
  background: #fdf0f6;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 24px 0;
}

footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  color: var(--muted);
}

footer button {
  padding: 4px 10px;
  color: var(--muted);
  background: none;
  text-decoration: underline;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.edit {
  padding: 4px 12px;
  color: var(--brand);
  background: var(--soft);
}

li input.edit-text {
  flex: 1;
  width: auto;
  height: auto;
  padding: 6px 10px;
  font: inherit;
  border: 2px solid var(--brand);
  border-radius: 10px;
}

Project 17.3 · Challenge

English and Arabic in one app

Add a button that switches every text in the app between English and Arabic, flips the layout from left-to-right to right-to-left, and remembers the choice.

You will practise: keeping texts as data, data-* attributes, functions stored in objects, lang and dir, and a second localStorage key.

Steps
  1. Create a TEXTS object with an en and an ar part, holding every word the app shows. left is a function, because the Arabic plural changes with the number.
  2. Write a tiny helper, t(key), that returns the text for the current language.
  3. In the HTML, mark each text with its key: <h1 data-text="title">. Add a language button in the header.
  4. Write applyLanguage(): set document.documentElement.lang and dir, fill every [data-text] element, set the placeholder and the labels, then render().
  5. Replace every fixed word in app.js with t(…), then delete the old leftText.
  6. The button switches language, saves it under its own key, and calls applyLanguage(). Reload the page: it should open in the last language you chose.

Hint: because the CSS uses flex and gap, and no fixed “left” or “right”, the whole layout mirrors itself when dir changes. Real apps keep their texts this way, which is how they are translated into many languages without touching the code.

Solution
languages/index.html↗ Open page⤓ File
<!doctype html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>My Tasks</title>
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    <main class="app">
      <header class="top">
        <h1 data-text="title">My Tasks</h1>
        <button type="button" id="language" lang="ar">العربية</button>
      </header>
      <p class="subtitle" data-text="subtitle">Small steps, every day.</p>

      <form id="new-task">
        <label for="task-text" class="visually-hidden" data-text="newTask">New task</label>
        <input id="task-text" type="text" placeholder="e.g. Read chapter 17" required>
        <button class="primary" type="submit" data-text="add">Add</button>
      </form>

      <div class="filters" role="group" aria-label="Show">
        <button type="button" data-filter="all" aria-pressed="true" data-text="all">All</button>
        <button type="button" data-filter="active" aria-pressed="false" data-text="active">To do</button>
        <button type="button" data-filter="done" aria-pressed="false" data-text="done">Done</button>
      </div>

      <ul id="tasks"></ul>
      <p class="empty" id="empty" data-text="empty">Nothing here yet. Add your first task above!</p>

      <footer>
        <span id="count" aria-live="polite"></span>
        <button type="button" id="clear" data-text="clear">Clear done</button>
      </footer>
    </main>
    <script src="app.js"></script>
  </body>
</html>
index.html560px
Project 17.3: one click, and the whole app speaks Arabic, right to left. The tasks themselves keep the words the user typed.
languages/app.js⤓ File
// ---------- Texts ----------
const TEXTS = {
  en: {
    title: "My Tasks",
    subtitle: "Small steps, every day.",
    newTask: "New task",
    placeholder: "e.g. Read chapter 17",
    add: "Add",
    show: "Show",
    all: "All",
    active: "To do",
    done: "Done",
    empty: "Nothing here yet. Add your first task above!",
    clear: "Clear done",
    delete: "Delete",
    switchTo: "العربية",
    left: (count) => {
      if (count === 0) return "All done!";
      if (count === 1) return "1 task left";
      return `${count} tasks left`;
    },
  },
  ar: {
    title: "مهامي",
    subtitle: "خطوات صغيرة، كل يوم.",
    newTask: "مهمة جديدة",
    placeholder: "مثلاً: اقرأ الفصل 17",
    add: "أضف",
    show: "اعرض",
    all: "الكل",
    active: "المتبقية",
    done: "المنجزة",
    empty: "لا شيء هنا بعد. أضف أول مهمة لك في الأعلى!",
    clear: "احذف المنجزة",
    delete: "احذف",
    switchTo: "English",
    left: (count) => {
      if (count === 0) return "أنجزت كل مهامك!";
      if (count === 1) return "بقيت مهمة واحدة";
      if (count === 2) return "بقيت مهمتان";
      if (count <= 10) return `بقيت ${count} مهام`;
      return `بقيت ${count} مهمة`;
    },
  },
};

const LANG_KEY = "my-tasks-language";
let language = localStorage.getItem(LANG_KEY) || "en";

function t(key) {
  return TEXTS[language][key];
}

function applyLanguage() {
  document.documentElement.lang = language;
  document.documentElement.dir = language === "ar" ? "rtl" : "ltr";
  document.title = t("title");

  for (const element of document.querySelectorAll("[data-text]")) {
    element.textContent = t(element.dataset.text);
  }
  document.querySelector("#task-text").placeholder = t("placeholder");
  document.querySelector(".filters").setAttribute("aria-label", t("show"));
  const button = document.querySelector("#language");
  button.textContent = t("switchTo");
  button.lang = language === "en" ? "ar" : "en";
  render();
}

function switchLanguage() {
  language = language === "en" ? "ar" : "en";
  localStorage.setItem(LANG_KEY, language);
  applyLanguage();
}

// ---------- Data ----------
const STORAGE_KEY = "my-tasks";
let tasks = load();
let filter = "all";

function load() {
  const saved = localStorage.getItem(STORAGE_KEY);
  return saved ? JSON.parse(saved) : [];
}

function save() {
  localStorage.setItem(STORAGE_KEY, JSON.stringify(tasks));
}

// ---------- Changes ----------
function addTask(text) {
  tasks.push({ id: Date.now(), text, done: false });
  update();
}

function toggleTask(id) {
  const task = tasks.find((t) => t.id === id);
  task.done = !task.done;
  update();
}

function deleteTask(id) {
  tasks = tasks.filter((t) => t.id !== id);
  update();
}

function clearDone() {
  tasks = tasks.filter((t) => !t.done);
  update();
}

function update() {
  save();
  render();
}

// ---------- Display ----------
function visibleTasks() {
  if (filter === "active") return tasks.filter((t) => !t.done);
  if (filter === "done") return tasks.filter((t) => t.done);
  return tasks;
}

function taskItem(task) {
  const li = document.createElement("li");
  li.classList.toggle("done", task.done);

  const box = document.createElement("input");
  box.type = "checkbox";
  box.id = `task-${task.id}`;
  box.checked = task.done;
  box.addEventListener("change", () => toggleTask(task.id));

  const label = document.createElement("label");
  label.htmlFor = box.id;
  label.textContent = task.text;

  const remove = document.createElement("button");
  remove.type = "button";
  remove.className = "delete";
  remove.textContent = t("delete");
  remove.setAttribute("aria-label", `${t("delete")}: ${task.text}`);
  remove.addEventListener("click", () => deleteTask(task.id));

  li.append(box, label, remove);
  return li;
}

function render() {
  const list = document.querySelector("#tasks");
  list.replaceChildren(...visibleTasks().map(taskItem));

  document.querySelector("#empty").hidden = tasks.length > 0;

  const count = tasks.filter((t) => !t.done).length;
  document.querySelector("#count").textContent = t("left")(count);

  for (const button of document.querySelectorAll("[data-filter]")) {
    button.setAttribute("aria-pressed", String(button.dataset.filter === filter));
  }
}

// ---------- Events ----------
document.querySelector("#new-task").addEventListener("submit", (event) => {
  event.preventDefault();
  const input = document.querySelector("#task-text");
  const text = input.value.trim();
  if (text) {
    addTask(text);
    input.value = "";
  }
  input.focus();
});

for (const button of document.querySelectorAll("[data-filter]")) {
  button.addEventListener("click", () => {
    filter = button.dataset.filter;
    render();
  });
}

document.querySelector("#clear").addEventListener("click", clearDone);
document.querySelector("#language").addEventListener("click", switchLanguage);

applyLanguage();
languages/style.css⤓ File
*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --brand: #4338ca;
  --accent: #db2777;
  --ink: #1e1b2e;
  --muted: #5b5873;
  --soft: #eef2ff;
}

body {
  margin: 0;
  font-family: system-ui, "Segoe UI", Tahoma, sans-serif;
  color: var(--ink);
  background: var(--soft);
}

.app {
  max-width: 560px;
  margin: 32px auto;
  padding: 24px;
  background: white;
  border-radius: 20px;
  box-shadow: 0 4px 20px rgba(30, 27, 46, 0.1);
}

h1 {
  margin: 0;
  color: var(--brand);
}

.subtitle {
  margin: 4px 0 20px;
  color: var(--muted);
}

form {
  display: flex;
  gap: 8px;
}

form input {
  flex: 1;
  padding: 10px 14px;
  font: inherit;
  border: 2px solid #c7c5dd;
  border-radius: 12px;
}

button {
  font: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 999px;
}

.primary {
  padding: 10px 20px;
  color: white;
  background: var(--brand);
}

.filters {
  display: flex;
  gap: 6px;
  margin: 18px 0 8px;
}

.filters button {
  padding: 6px 14px;
  color: var(--brand);
  background: var(--soft);
}

.filters button[aria-pressed="true"] {
  color: white;
  background: var(--brand);
}

ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--soft);
}

li label {
  flex: 1;
}

li.done label {
  color: var(--muted);
  text-decoration: line-through;
}

li input {
  width: 20px;
  height: 20px;
  accent-color: var(--brand);
}

.delete {
  padding: 4px 12px;
  color: var(--accent);
  background: #fdf0f6;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 24px 0;
}

footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  color: var(--muted);
}

footer button {
  padding: 4px 10px;
  color: var(--muted);
  background: none;
  text-decoration: underline;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

#language {
  padding: 6px 14px;
  color: var(--brand);
  background: var(--soft);
}

Exercises

Exercise 17.1 · Easy

Change the colours and the title of the app to make it your own, and publish the new version with a single git push.
The book's short answer
Change the custom properties and the <h1>, commit, and git push; GitHub Pages updates within a minute.
Show the solution
index.html↗ Open page⤓ File
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Sara’s Steps</title>
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    <main class="app">
      <h1>Sara’s Steps</h1>
      <p class="subtitle">One green tick at a time.</p>

      <form id="new-task">
        <label for="task-text" class="visually-hidden">New task</label>
        <input id="task-text" type="text" placeholder="e.g. Read chapter 17" required>
        <button class="primary" type="submit">Add</button>
      </form>

      <div class="filters" role="group" aria-label="Show">
        <button type="button" data-filter="all" aria-pressed="true">All</button>
        <button type="button" data-filter="active" aria-pressed="false">To do</button>
        <button type="button" data-filter="done" aria-pressed="false">Done</button>
      </div>

      <ul id="tasks"></ul>
      <p class="empty" id="empty">Nothing here yet. Add your first task above!</p>

      <footer>
        <span id="count" aria-live="polite"></span>
        <button type="button" id="clear">Clear done</button>
      </footer>
    </main>
    <script src="app.js"></script>
  </body>
</html>
index.html640px
app.js⤓ File
// ---------- Data ----------
const STORAGE_KEY = "my-tasks-ex1";
let tasks = load();
let filter = "all";

function load() {
  const saved = localStorage.getItem(STORAGE_KEY);
  return saved ? JSON.parse(saved) : [];
}

function save() {
  localStorage.setItem(STORAGE_KEY, JSON.stringify(tasks));
}

// ---------- Changes ----------
function addTask(text) {
  tasks.push({ id: Date.now(), text, done: false });
  update();
}

function toggleTask(id) {
  const task = tasks.find((t) => t.id === id);
  task.done = !task.done;
  update();
}

function deleteTask(id) {
  tasks = tasks.filter((t) => t.id !== id);
  update();
}

function clearDone() {
  tasks = tasks.filter((t) => !t.done);
  update();
}

function update() {
  save();
  render();
}

// ---------- Display ----------
function visibleTasks() {
  if (filter === "active") return tasks.filter((t) => !t.done);
  if (filter === "done") return tasks.filter((t) => t.done);
  return tasks;
}

function taskItem(task) {
  const li = document.createElement("li");
  li.classList.toggle("done", task.done);

  const box = document.createElement("input");
  box.type = "checkbox";
  box.id = `task-${task.id}`;
  box.checked = task.done;
  box.addEventListener("change", () => toggleTask(task.id));

  const label = document.createElement("label");
  label.htmlFor = box.id;
  label.textContent = task.text;

  const remove = document.createElement("button");
  remove.type = "button";
  remove.className = "delete";
  remove.textContent = "Delete";
  remove.setAttribute("aria-label", `Delete: ${task.text}`);
  remove.addEventListener("click", () => deleteTask(task.id));

  li.append(box, label, remove);
  return li;
}

function leftText(count) {
  if (count === 0) return "All done!";
  if (count === 1) return "1 task left";
  return `${count} tasks left`;
}

function render() {
  const list = document.querySelector("#tasks");
  list.replaceChildren(...visibleTasks().map(taskItem));

  document.querySelector("#empty").hidden = tasks.length > 0;

  const count = tasks.filter((t) => !t.done).length;
  document.querySelector("#count").textContent = leftText(count);

  for (const button of document.querySelectorAll("[data-filter]")) {
    button.setAttribute("aria-pressed", String(button.dataset.filter === filter));
  }
}

// ---------- Events ----------
document.querySelector("#new-task").addEventListener("submit", (event) => {
  event.preventDefault();
  const input = document.querySelector("#task-text");
  const text = input.value.trim();
  if (text) {
    addTask(text);
    input.value = "";
  }
  input.focus();
});

for (const button of document.querySelectorAll("[data-filter]")) {
  button.addEventListener("click", () => {
    filter = button.dataset.filter;
    render();
  });
}

document.querySelector("#clear").addEventListener("click", clearDone);

render();
publish.sh⤓ File
Runs in a terminal: bash publish.sh
#!/usr/bin/env bash
# Publishing the new version is one commit and one push; GitHub Pages updates within a minute.
# Run it inside your app's repository (the one you published in Chapter 17).
# lab: do not run (it pushes to your own repository, so the lab only shows it)
set -e
git add index.html style.css
git commit -m "Make the app my own: new title and colours"
git push
style.css⤓ File
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* The whole theme comes from these custom properties: changing four lines changes the app. */
:root {
  --brand: #0f766e;
  --accent: #c2410c;
  --ink: #1e1b2e;
  --muted: #5b5873;
  --soft: #ecfdf5;
}

body {
  margin: 0;
  font-family: system-ui, "Segoe UI", Tahoma, sans-serif;
  color: var(--ink);
  background: var(--soft);
}

.app {
  max-width: 560px;
  margin: 32px auto;
  padding: 24px;
  background: white;
  border-radius: 20px;
  box-shadow: 0 4px 20px rgba(30, 27, 46, 0.1);
}

h1 {
  margin: 0;
  color: var(--brand);
}

.subtitle {
  margin: 4px 0 20px;
  color: var(--muted);
}

form {
  display: flex;
  gap: 8px;
}

form input {
  flex: 1;
  padding: 10px 14px;
  font: inherit;
  border: 2px solid #c7c5dd;
  border-radius: 12px;
}

button {
  font: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 999px;
}

.primary {
  padding: 10px 20px;
  color: white;
  background: var(--brand);
}

.filters {
  display: flex;
  gap: 6px;
  margin: 18px 0 8px;
}

.filters button {
  padding: 6px 14px;
  color: var(--brand);
  background: var(--soft);
}

.filters button[aria-pressed="true"] {
  color: white;
  background: var(--brand);
}

ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--soft);
}

li label {
  flex: 1;
}

li.done label {
  color: var(--muted);
  text-decoration: line-through;
}

li input {
  width: 20px;
  height: 20px;
  accent-color: var(--brand);
}

.delete {
  padding: 4px 12px;
  color: var(--accent);
  background: #fdf0f6;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 24px 0;
}

footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  color: var(--muted);
}

footer button {
  padding: 4px 10px;
  color: var(--muted);
  background: none;
  text-decoration: underline;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

Exercise 17.2 · Easy

Add a counter of finished tasks next to the counter of tasks left.
The book's short answer
Count tasks.filter((t) => t.done).length in render and show it in a new element.
Show the solution
index.html↗ Open page⤓ File
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>My Tasks</title>
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    <main class="app">
      <h1>My Tasks</h1>
      <p class="subtitle">Small steps, every day.</p>

      <form id="new-task">
        <label for="task-text" class="visually-hidden">New task</label>
        <input id="task-text" type="text" placeholder="e.g. Read chapter 17" required>
        <button class="primary" type="submit">Add</button>
      </form>

      <div class="filters" role="group" aria-label="Show">
        <button type="button" data-filter="all" aria-pressed="true">All</button>
        <button type="button" data-filter="active" aria-pressed="false">To do</button>
        <button type="button" data-filter="done" aria-pressed="false">Done</button>
      </div>

      <ul id="tasks"></ul>
      <p class="empty" id="empty">Nothing here yet. Add your first task above!</p>

      <footer>
        <span id="count" aria-live="polite"></span>
        <span id="finished"></span>
        <button type="button" id="clear">Clear done</button>
      </footer>
    </main>
    <script src="app.js"></script>
  </body>
</html>
index.html640px
app.js⤓ File
// ---------- Data ----------
const STORAGE_KEY = "my-tasks-ex2";
let tasks = load();
let filter = "all";

function load() {
  const saved = localStorage.getItem(STORAGE_KEY);
  return saved ? JSON.parse(saved) : [];
}

function save() {
  localStorage.setItem(STORAGE_KEY, JSON.stringify(tasks));
}

// ---------- Changes ----------
function addTask(text) {
  tasks.push({ id: Date.now(), text, done: false });
  update();
}

function toggleTask(id) {
  const task = tasks.find((t) => t.id === id);
  task.done = !task.done;
  update();
}

function deleteTask(id) {
  tasks = tasks.filter((t) => t.id !== id);
  update();
}

function clearDone() {
  tasks = tasks.filter((t) => !t.done);
  update();
}

function update() {
  save();
  render();
}

// ---------- Display ----------
function visibleTasks() {
  if (filter === "active") return tasks.filter((t) => !t.done);
  if (filter === "done") return tasks.filter((t) => t.done);
  return tasks;
}

function taskItem(task) {
  const li = document.createElement("li");
  li.classList.toggle("done", task.done);

  const box = document.createElement("input");
  box.type = "checkbox";
  box.id = `task-${task.id}`;
  box.checked = task.done;
  box.addEventListener("change", () => toggleTask(task.id));

  const label = document.createElement("label");
  label.htmlFor = box.id;
  label.textContent = task.text;

  const remove = document.createElement("button");
  remove.type = "button";
  remove.className = "delete";
  remove.textContent = "Delete";
  remove.setAttribute("aria-label", `Delete: ${task.text}`);
  remove.addEventListener("click", () => deleteTask(task.id));

  li.append(box, label, remove);
  return li;
}

function leftText(count) {
  if (count === 0) return "All done!";
  if (count === 1) return "1 task left";
  return `${count} tasks left`;
}

function render() {
  const list = document.querySelector("#tasks");
  list.replaceChildren(...visibleTasks().map(taskItem));

  document.querySelector("#empty").hidden = tasks.length > 0;

  const count = tasks.filter((t) => !t.done).length;
  document.querySelector("#count").textContent = leftText(count);

  // The other side of the same data: the tasks that are done.
  const finished = tasks.filter((t) => t.done).length;
  document.querySelector("#finished").textContent = `Done: ${finished}`;

  for (const button of document.querySelectorAll("[data-filter]")) {
    button.setAttribute("aria-pressed", String(button.dataset.filter === filter));
  }
}

// ---------- Events ----------
document.querySelector("#new-task").addEventListener("submit", (event) => {
  event.preventDefault();
  const input = document.querySelector("#task-text");
  const text = input.value.trim();
  if (text) {
    addTask(text);
    input.value = "";
  }
  input.focus();
});

for (const button of document.querySelectorAll("[data-filter]")) {
  button.addEventListener("click", () => {
    filter = button.dataset.filter;
    render();
  });
}

document.querySelector("#clear").addEventListener("click", clearDone);

render();
style.css⤓ File
*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --brand: #4338ca;
  --accent: #db2777;
  --ink: #1e1b2e;
  --muted: #5b5873;
  --soft: #eef2ff;
}

body {
  margin: 0;
  font-family: system-ui, "Segoe UI", Tahoma, sans-serif;
  color: var(--ink);
  background: var(--soft);
}

.app {
  max-width: 560px;
  margin: 32px auto;
  padding: 24px;
  background: white;
  border-radius: 20px;
  box-shadow: 0 4px 20px rgba(30, 27, 46, 0.1);
}

h1 {
  margin: 0;
  color: var(--brand);
}

.subtitle {
  margin: 4px 0 20px;
  color: var(--muted);
}

form {
  display: flex;
  gap: 8px;
}

form input {
  flex: 1;
  padding: 10px 14px;
  font: inherit;
  border: 2px solid #c7c5dd;
  border-radius: 12px;
}

button {
  font: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 999px;
}

.primary {
  padding: 10px 20px;
  color: white;
  background: var(--brand);
}

.filters {
  display: flex;
  gap: 6px;
  margin: 18px 0 8px;
}

.filters button {
  padding: 6px 14px;
  color: var(--brand);
  background: var(--soft);
}

.filters button[aria-pressed="true"] {
  color: white;
  background: var(--brand);
}

ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--soft);
}

li label {
  flex: 1;
}

li.done label {
  color: var(--muted);
  text-decoration: line-through;
}

li input {
  width: 20px;
  height: 20px;
  accent-color: var(--brand);
}

.delete {
  padding: 4px 12px;
  color: var(--accent);
  background: #fdf0f6;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 24px 0;
}

footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  color: var(--muted);
}

#finished {
  margin-inline-start: auto;
  margin-inline-end: 12px;
  color: #15803d;
  font-weight: 700;
}

footer button {
  padding: 4px 10px;
  color: var(--muted);
  background: none;
  text-decoration: underline;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

Exercise 17.3 · Medium

Let the user edit a task’s text by double-clicking it. Save the change with Enter and cancel with Escape.
The book's short answer
On dblclick, replace the label with an <input>; on keydown, save on Enter (update the task’s text and call update()) and cancel on Escape (call render()).
Show the solution
index.html↗ Open page⤓ File
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>My Tasks</title>
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    <main class="app">
      <h1>My Tasks</h1>
      <p class="subtitle">Small steps, every day.</p>

      <form id="new-task">
        <label for="task-text" class="visually-hidden">New task</label>
        <input id="task-text" type="text" placeholder="e.g. Read chapter 17" required>
        <button class="primary" type="submit">Add</button>
      </form>

      <div class="filters" role="group" aria-label="Show">
        <button type="button" data-filter="all" aria-pressed="true">All</button>
        <button type="button" data-filter="active" aria-pressed="false">To do</button>
        <button type="button" data-filter="done" aria-pressed="false">Done</button>
      </div>

      <p class="hint">Double-click a task to edit it. Enter saves, Escape cancels.</p>
      <ul id="tasks"></ul>
      <p class="empty" id="empty">Nothing here yet. Add your first task above!</p>

      <footer>
        <span id="count" aria-live="polite"></span>
        <button type="button" id="clear">Clear done</button>
      </footer>
    </main>
    <script src="app.js"></script>
  </body>
</html>
index.html640px
app.js⤓ File
// ---------- Data ----------
const STORAGE_KEY = "my-tasks-ex3";
let tasks = load();
let filter = "all";

function load() {
  const saved = localStorage.getItem(STORAGE_KEY);
  return saved ? JSON.parse(saved) : [];
}

function save() {
  localStorage.setItem(STORAGE_KEY, JSON.stringify(tasks));
}

// ---------- Changes ----------
function addTask(text) {
  tasks.push({ id: Date.now(), text, done: false });
  update();
}

function toggleTask(id) {
  const task = tasks.find((t) => t.id === id);
  task.done = !task.done;
  update();
}

function editTask(id, text) {
  const task = tasks.find((t) => t.id === id);
  task.text = text;
  update();
}

function deleteTask(id) {
  tasks = tasks.filter((t) => t.id !== id);
  update();
}

function clearDone() {
  tasks = tasks.filter((t) => !t.done);
  update();
}

function update() {
  save();
  render();
}

// ---------- Display ----------
function visibleTasks() {
  if (filter === "active") return tasks.filter((t) => !t.done);
  if (filter === "done") return tasks.filter((t) => t.done);
  return tasks;
}

function taskItem(task) {
  const li = document.createElement("li");
  li.classList.toggle("done", task.done);

  const box = document.createElement("input");
  box.type = "checkbox";
  box.id = `task-${task.id}`;
  box.checked = task.done;
  box.addEventListener("change", () => toggleTask(task.id));

  const label = document.createElement("label");
  // The text is no longer a <label for> the box: a label would tick the box on each of the two clicks of a
  // double-click. aria-labelledby still gives the box its name.
  label.id = `text-${task.id}`;
  box.setAttribute("aria-labelledby", label.id);
  label.textContent = task.text;
  // Double-click: swap the label for a text field with the same text.
  label.addEventListener("dblclick", (event) => {
    startEditing(task, label);
  });

  const remove = document.createElement("button");
  remove.type = "button";
  remove.className = "delete";
  remove.textContent = "Delete";
  remove.setAttribute("aria-label", `Delete: ${task.text}`);
  remove.addEventListener("click", () => deleteTask(task.id));

  li.append(box, label, remove);
  return li;
}

function startEditing(task, label) {
  const field = document.createElement("input");
  field.type = "text";
  field.className = "edit-text";
  field.value = task.text;
  field.setAttribute("aria-label", `Edit: ${task.text}`);
  label.replaceWith(field);
  field.focus();
  field.select();

  field.addEventListener("keydown", (event) => {
    if (event.key === "Enter") {
      const text = field.value.trim();
      // An empty text would leave an invisible task: keep the old one instead.
      if (text) editTask(task.id, text);
      else render();
    } else if (event.key === "Escape") {
      render(); // drawing again from the data throws the edit away
    }
  });
  field.addEventListener("blur", () => render());
}

function leftText(count) {
  if (count === 0) return "All done!";
  if (count === 1) return "1 task left";
  return `${count} tasks left`;
}

function render() {
  const list = document.querySelector("#tasks");
  list.replaceChildren(...visibleTasks().map(taskItem));

  document.querySelector("#empty").hidden = tasks.length > 0;

  const count = tasks.filter((t) => !t.done).length;
  document.querySelector("#count").textContent = leftText(count);

  for (const button of document.querySelectorAll("[data-filter]")) {
    button.setAttribute("aria-pressed", String(button.dataset.filter === filter));
  }
}

// ---------- Events ----------
document.querySelector("#new-task").addEventListener("submit", (event) => {
  event.preventDefault();
  const input = document.querySelector("#task-text");
  const text = input.value.trim();
  if (text) {
    addTask(text);
    input.value = "";
  }
  input.focus();
});

for (const button of document.querySelectorAll("[data-filter]")) {
  button.addEventListener("click", () => {
    filter = button.dataset.filter;
    render();
  });
}

document.querySelector("#clear").addEventListener("click", clearDone);

render();
style.css⤓ File
*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --brand: #4338ca;
  --accent: #db2777;
  --ink: #1e1b2e;
  --muted: #5b5873;
  --soft: #eef2ff;
}

body {
  margin: 0;
  font-family: system-ui, "Segoe UI", Tahoma, sans-serif;
  color: var(--ink);
  background: var(--soft);
}

.app {
  max-width: 560px;
  margin: 32px auto;
  padding: 24px;
  background: white;
  border-radius: 20px;
  box-shadow: 0 4px 20px rgba(30, 27, 46, 0.1);
}

h1 {
  margin: 0;
  color: var(--brand);
}

.subtitle {
  margin: 4px 0 20px;
  color: var(--muted);
}

form {
  display: flex;
  gap: 8px;
}

form input {
  flex: 1;
  padding: 10px 14px;
  font: inherit;
  border: 2px solid #c7c5dd;
  border-radius: 12px;
}

button {
  font: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 999px;
}

.primary {
  padding: 10px 20px;
  color: white;
  background: var(--brand);
}

.filters {
  display: flex;
  gap: 6px;
  margin: 18px 0 8px;
}

.filters button {
  padding: 6px 14px;
  color: var(--brand);
  background: var(--soft);
}

.filters button[aria-pressed="true"] {
  color: white;
  background: var(--brand);
}

ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--soft);
}

li label {
  flex: 1;
}

li.done label {
  color: var(--muted);
  text-decoration: line-through;
}

li input {
  width: 20px;
  height: 20px;
  accent-color: var(--brand);
}

.edit-text {
  flex: 1;
  padding: 4px 8px;
  font: inherit;
  border: 2px solid var(--brand);
  border-radius: 8px;
}

.hint {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

.delete {
  padding: 4px 12px;
  color: var(--accent);
  background: #fdf0f6;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 24px 0;
}

footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  color: var(--muted);
}

footer button {
  padding: 4px 10px;
  color: var(--muted);
  background: none;
  text-decoration: underline;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

Exercise 17.4 · Medium

Add a “priority” to each task (low, normal, high), chosen with a <select> when adding, and show high-priority tasks first.
The book's short answer
Add a <select> to the form, store priority in each task, and sort the visible tasks with sort((a, b) => rank[b.priority] - rank[a.priority]).
Show the solution
index.html↗ Open page⤓ File
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>My Tasks</title>
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    <main class="app">
      <h1>My Tasks</h1>
      <p class="subtitle">Small steps, every day.</p>

      <form id="new-task">
        <label for="task-text" class="visually-hidden">New task</label>
        <input id="task-text" type="text" placeholder="e.g. Read chapter 17" required>
        <label for="priority" class="visually-hidden">Priority</label>
        <select id="priority">
          <option value="low">Low</option>
          <option value="normal" selected>Normal</option>
          <option value="high">High</option>
        </select>
        <button class="primary" type="submit">Add</button>
      </form>

      <div class="filters" role="group" aria-label="Show">
        <button type="button" data-filter="all" aria-pressed="true">All</button>
        <button type="button" data-filter="active" aria-pressed="false">To do</button>
        <button type="button" data-filter="done" aria-pressed="false">Done</button>
      </div>

      <ul id="tasks"></ul>
      <p class="empty" id="empty">Nothing here yet. Add your first task above!</p>

      <footer>
        <span id="count" aria-live="polite"></span>
        <button type="button" id="clear">Clear done</button>
      </footer>
    </main>
    <script src="app.js"></script>
  </body>
</html>
index.html640px
app.js⤓ File
// ---------- Data ----------
const STORAGE_KEY = "my-tasks-ex4";

// A number for each priority, so tasks can be sorted by it.
const rank = { high: 3, normal: 2, low: 1 };
const priorityNames = { high: "High", normal: "Normal", low: "Low" };
let tasks = load();
let filter = "all";

function load() {
  const saved = localStorage.getItem(STORAGE_KEY);
  return saved ? JSON.parse(saved) : [];
}

function save() {
  localStorage.setItem(STORAGE_KEY, JSON.stringify(tasks));
}

// ---------- Changes ----------
function addTask(text, priority) {
  tasks.push({ id: Date.now(), text, done: false, priority });
  update();
}

function toggleTask(id) {
  const task = tasks.find((t) => t.id === id);
  task.done = !task.done;
  update();
}

function deleteTask(id) {
  tasks = tasks.filter((t) => t.id !== id);
  update();
}

function clearDone() {
  tasks = tasks.filter((t) => !t.done);
  update();
}

function update() {
  save();
  render();
}

// ---------- Display ----------
function visibleTasks() {
  let list = tasks;
  if (filter === "active") list = tasks.filter((t) => !t.done);
  if (filter === "done") list = tasks.filter((t) => t.done);
  // High first. sort changes the array it is given, so sort a copy ([...list]) and keep the saved order.
  // Tasks saved before this change have no priority: ?? treats them as normal.
  return [...list].sort((a, b) => rank[b.priority ?? "normal"] - rank[a.priority ?? "normal"]);
}

function taskItem(task) {
  const li = document.createElement("li");
  li.classList.toggle("done", task.done);

  const box = document.createElement("input");
  box.type = "checkbox";
  box.id = `task-${task.id}`;
  box.checked = task.done;
  box.addEventListener("change", () => toggleTask(task.id));

  const label = document.createElement("label");
  label.htmlFor = box.id;
  label.textContent = task.text;

  const priority = task.priority ?? "normal";
  const badge = document.createElement("span");
  badge.className = `badge ${priority}`;
  badge.textContent = priorityNames[priority];

  const remove = document.createElement("button");
  remove.type = "button";
  remove.className = "delete";
  remove.textContent = "Delete";
  remove.setAttribute("aria-label", `Delete: ${task.text}`);
  remove.addEventListener("click", () => deleteTask(task.id));

  li.append(box, label, badge, remove);
  return li;
}

function leftText(count) {
  if (count === 0) return "All done!";
  if (count === 1) return "1 task left";
  return `${count} tasks left`;
}

function render() {
  const list = document.querySelector("#tasks");
  list.replaceChildren(...visibleTasks().map(taskItem));

  document.querySelector("#empty").hidden = tasks.length > 0;

  const count = tasks.filter((t) => !t.done).length;
  document.querySelector("#count").textContent = leftText(count);

  for (const button of document.querySelectorAll("[data-filter]")) {
    button.setAttribute("aria-pressed", String(button.dataset.filter === filter));
  }
}

// ---------- Events ----------
document.querySelector("#new-task").addEventListener("submit", (event) => {
  event.preventDefault();
  const input = document.querySelector("#task-text");
  const text = input.value.trim();
  if (text) {
    addTask(text, document.querySelector("#priority").value);
    input.value = "";
  }
  input.focus();
});

for (const button of document.querySelectorAll("[data-filter]")) {
  button.addEventListener("click", () => {
    filter = button.dataset.filter;
    render();
  });
}

document.querySelector("#clear").addEventListener("click", clearDone);

render();
style.css⤓ File
*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --brand: #4338ca;
  --accent: #db2777;
  --ink: #1e1b2e;
  --muted: #5b5873;
  --soft: #eef2ff;
}

body {
  margin: 0;
  font-family: system-ui, "Segoe UI", Tahoma, sans-serif;
  color: var(--ink);
  background: var(--soft);
}

.app {
  max-width: 560px;
  margin: 32px auto;
  padding: 24px;
  background: white;
  border-radius: 20px;
  box-shadow: 0 4px 20px rgba(30, 27, 46, 0.1);
}

h1 {
  margin: 0;
  color: var(--brand);
}

.subtitle {
  margin: 4px 0 20px;
  color: var(--muted);
}

form {
  display: flex;
  gap: 8px;
}

form input {
  flex: 1;
  padding: 10px 14px;
  font: inherit;
  border: 2px solid #c7c5dd;
  border-radius: 12px;
}

button {
  font: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 999px;
}

.primary {
  padding: 10px 20px;
  color: white;
  background: var(--brand);
}

.filters {
  display: flex;
  gap: 6px;
  margin: 18px 0 8px;
}

.filters button {
  padding: 6px 14px;
  color: var(--brand);
  background: var(--soft);
}

.filters button[aria-pressed="true"] {
  color: white;
  background: var(--brand);
}

ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--soft);
}

li label {
  flex: 1;
}

li.done label {
  color: var(--muted);
  text-decoration: line-through;
}

li input {
  width: 20px;
  height: 20px;
  accent-color: var(--brand);
}

form select {
  padding: 8px;
  font: inherit;
  border: 2px solid #c7c5dd;
  border-radius: 12px;
  background: white;
}

.badge {
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
}

.badge.high { color: #b91c1c; background: #fee2e2; }
.badge.normal { color: #4338ca; background: #e0e7ff; }
.badge.low { color: #4b5563; background: #f3f4f6; }

.delete {
  padding: 4px 12px;
  color: var(--accent);
  background: #fdf0f6;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 24px 0;
}

footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  color: var(--muted);
}

footer button {
  padding: 4px 10px;
  color: var(--muted);
  background: none;
  text-decoration: underline;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

Exercise 17.5 · Challenge

Add a language switch to the app. Keep all texts in an object like { en: {…}, ar: {…} }, remember the choice in localStorage, and update lang and dir on the <html> element.
The book's short answer
Keep the texts in one object, write a function that fills every element from the chosen language, save the choice in localStorage, and set document.documentElement.lang and .dir.
Show the solution

This exercise is the same work as the chapter's practice project "A language switch", so the solution starts from that project. How it meets each part of the exercise:

  • All texts in one object: TEXTS = { en: {…}, ar: {…} } at the top of app.js. The Arabic "tasks left" text is a function, because Arabic changes the word with the number (one, two, 3 to 10, 11 and more).
  • One function fills the page: applyLanguage() writes the text of every element that has a data-text attribute, the placeholder and the page title.
  • The choice is remembered: localStorage.setItem("my-tasks-language", language).
  • lang and dir: document.documentElement.lang and .dir change, so the whole layout flips to right-to-left with no extra CSS (the stylesheet uses inline-start/inline-end, which follow the direction).
index.html↗ Open page⤓ File
<!doctype html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>My Tasks</title>
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    <main class="app">
      <header class="top">
        <h1 data-text="title">My Tasks</h1>
        <button type="button" id="language" lang="ar">العربية</button>
      </header>
      <p class="subtitle" data-text="subtitle">Small steps, every day.</p>

      <form id="new-task">
        <label for="task-text" class="visually-hidden" data-text="newTask">New task</label>
        <input id="task-text" type="text" placeholder="e.g. Read chapter 17" required>
        <button class="primary" type="submit" data-text="add">Add</button>
      </form>

      <div class="filters" role="group" aria-label="Show">
        <button type="button" data-filter="all" aria-pressed="true" data-text="all">All</button>
        <button type="button" data-filter="active" aria-pressed="false" data-text="active">To do</button>
        <button type="button" data-filter="done" aria-pressed="false" data-text="done">Done</button>
      </div>

      <ul id="tasks"></ul>
      <p class="empty" id="empty" data-text="empty">Nothing here yet. Add your first task above!</p>

      <footer>
        <span id="count" aria-live="polite"></span>
        <button type="button" id="clear" data-text="clear">Clear done</button>
      </footer>
    </main>
    <script src="app.js"></script>
  </body>
</html>
index.html640px
app.js⤓ File
// ---------- Texts ----------
const TEXTS = {
  en: {
    title: "My Tasks",
    subtitle: "Small steps, every day.",
    newTask: "New task",
    placeholder: "e.g. Read chapter 17",
    add: "Add",
    show: "Show",
    all: "All",
    active: "To do",
    done: "Done",
    empty: "Nothing here yet. Add your first task above!",
    clear: "Clear done",
    delete: "Delete",
    switchTo: "العربية",
    left: (count) => {
      if (count === 0) return "All done!";
      if (count === 1) return "1 task left";
      return `${count} tasks left`;
    },
  },
  ar: {
    title: "مهامي",
    subtitle: "خطوات صغيرة، كل يوم.",
    newTask: "مهمة جديدة",
    placeholder: "مثلاً: اقرأ الفصل 17",
    add: "أضف",
    show: "اعرض",
    all: "الكل",
    active: "المتبقية",
    done: "المنجزة",
    empty: "لا شيء هنا بعد. أضف أول مهمة لك في الأعلى!",
    clear: "احذف المنجزة",
    delete: "احذف",
    switchTo: "English",
    left: (count) => {
      if (count === 0) return "أنجزت كل مهامك!";
      if (count === 1) return "بقيت مهمة واحدة";
      if (count === 2) return "بقيت مهمتان";
      if (count <= 10) return `بقيت ${count} مهام`;
      return `بقيت ${count} مهمة`;
    },
  },
};

const LANG_KEY = "my-tasks-language";
let language = localStorage.getItem(LANG_KEY) || "en";

function t(key) {
  return TEXTS[language][key];
}

function applyLanguage() {
  document.documentElement.lang = language;
  document.documentElement.dir = language === "ar" ? "rtl" : "ltr";
  document.title = t("title");

  for (const element of document.querySelectorAll("[data-text]")) {
    element.textContent = t(element.dataset.text);
  }
  document.querySelector("#task-text").placeholder = t("placeholder");
  document.querySelector(".filters").setAttribute("aria-label", t("show"));
  const button = document.querySelector("#language");
  button.textContent = t("switchTo");
  button.lang = language === "en" ? "ar" : "en";
  render();
}

function switchLanguage() {
  language = language === "en" ? "ar" : "en";
  localStorage.setItem(LANG_KEY, language);
  applyLanguage();
}

// ---------- Data ----------
const STORAGE_KEY = "my-tasks-ex5";
let tasks = load();
let filter = "all";

function load() {
  const saved = localStorage.getItem(STORAGE_KEY);
  return saved ? JSON.parse(saved) : [];
}

function save() {
  localStorage.setItem(STORAGE_KEY, JSON.stringify(tasks));
}

// ---------- Changes ----------
function addTask(text) {
  tasks.push({ id: Date.now(), text, done: false });
  update();
}

function toggleTask(id) {
  const task = tasks.find((t) => t.id === id);
  task.done = !task.done;
  update();
}

function deleteTask(id) {
  tasks = tasks.filter((t) => t.id !== id);
  update();
}

function clearDone() {
  tasks = tasks.filter((t) => !t.done);
  update();
}

function update() {
  save();
  render();
}

// ---------- Display ----------
function visibleTasks() {
  if (filter === "active") return tasks.filter((t) => !t.done);
  if (filter === "done") return tasks.filter((t) => t.done);
  return tasks;
}

function taskItem(task) {
  const li = document.createElement("li");
  li.classList.toggle("done", task.done);

  const box = document.createElement("input");
  box.type = "checkbox";
  box.id = `task-${task.id}`;
  box.checked = task.done;
  box.addEventListener("change", () => toggleTask(task.id));

  const label = document.createElement("label");
  label.htmlFor = box.id;
  label.textContent = task.text;

  const remove = document.createElement("button");
  remove.type = "button";
  remove.className = "delete";
  remove.textContent = t("delete");
  remove.setAttribute("aria-label", `${t("delete")}: ${task.text}`);
  remove.addEventListener("click", () => deleteTask(task.id));

  li.append(box, label, remove);
  return li;
}

function render() {
  const list = document.querySelector("#tasks");
  list.replaceChildren(...visibleTasks().map(taskItem));

  document.querySelector("#empty").hidden = tasks.length > 0;

  const count = tasks.filter((t) => !t.done).length;
  document.querySelector("#count").textContent = t("left")(count);

  for (const button of document.querySelectorAll("[data-filter]")) {
    button.setAttribute("aria-pressed", String(button.dataset.filter === filter));
  }
}

// ---------- Events ----------
document.querySelector("#new-task").addEventListener("submit", (event) => {
  event.preventDefault();
  const input = document.querySelector("#task-text");
  const text = input.value.trim();
  if (text) {
    addTask(text);
    input.value = "";
  }
  input.focus();
});

for (const button of document.querySelectorAll("[data-filter]")) {
  button.addEventListener("click", () => {
    filter = button.dataset.filter;
    render();
  });
}

document.querySelector("#clear").addEventListener("click", clearDone);
document.querySelector("#language").addEventListener("click", switchLanguage);

applyLanguage();
style.css⤓ File
*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --brand: #4338ca;
  --accent: #db2777;
  --ink: #1e1b2e;
  --muted: #5b5873;
  --soft: #eef2ff;
}

body {
  margin: 0;
  font-family: system-ui, "Segoe UI", Tahoma, sans-serif;
  color: var(--ink);
  background: var(--soft);
}

.app {
  max-width: 560px;
  margin: 32px auto;
  padding: 24px;
  background: white;
  border-radius: 20px;
  box-shadow: 0 4px 20px rgba(30, 27, 46, 0.1);
}

h1 {
  margin: 0;
  color: var(--brand);
}

.subtitle {
  margin: 4px 0 20px;
  color: var(--muted);
}

form {
  display: flex;
  gap: 8px;
}

form input {
  flex: 1;
  padding: 10px 14px;
  font: inherit;
  border: 2px solid #c7c5dd;
  border-radius: 12px;
}

button {
  font: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 999px;
}

.primary {
  padding: 10px 20px;
  color: white;
  background: var(--brand);
}

.filters {
  display: flex;
  gap: 6px;
  margin: 18px 0 8px;
}

.filters button {
  padding: 6px 14px;
  color: var(--brand);
  background: var(--soft);
}

.filters button[aria-pressed="true"] {
  color: white;
  background: var(--brand);
}

ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--soft);
}

li label {
  flex: 1;
}

li.done label {
  color: var(--muted);
  text-decoration: line-through;
}

li input {
  width: 20px;
  height: 20px;
  accent-color: var(--brand);
}

.delete {
  padding: 4px 12px;
  color: var(--accent);
  background: #fdf0f6;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 24px 0;
}

footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  color: var(--muted);
}

footer button {
  padding: 4px 10px;
  color: var(--muted);
  background: none;
  text-decoration: underline;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

#language {
  padding: 6px 14px;
  color: var(--brand);
  background: var(--soft);
}