JavaScript · Level 1 Project

Project: Todo Summary

Combine a loop, objects and a condition to write the status line under a todo list, the kind every task app shows.

  • Looping over an array of objects
  • Checking for an empty array with length === 0

Each todo is an object, so loop over the array and read todo.done. The trap: list == [] is always false, because arrays are compared by identity. Check list.length === 0 instead.

const todos = [{ title: "Email", done: true }];
todos == [];             // false, even for an empty list
todos.length === 0;      // false
for (const todo of todos) {
  console.log(todo.title, todo.done);  // Email true
}

Write summary(todos) that returns "<done> of <total> done", or "Nothing to do" for an empty list, e.g. three todos with two done return 2 of 3 done.

solution.js
Test Suites Pending
Output