Syncing account progress…

Back

Beginner · 9 min

Project: a study plan

Combine filtering, totals, and message formatting to summarize a plan.

Select unfinished sessions

Represent sessions as objects so each one can store a title, duration, and completion flag. Filter the collection before summarizing it.

const sessions = [{ title: "Read", minutes: 10, done: true }, { title: "Practice", minutes: 20, done: false }];
const remaining = sessions.filter(session => !session.done);
console.log(remaining.map(session => session.title).join(", "));

Output

Practice

Summarize the plan

A loop can total the selected durations. Format the result only after completing the calculation.

const sessions = [{ minutes: 15 }, { minutes: 20 }];
let minutes = 0;
for (const session of sessions) { minutes += session.minutes; }
console.log(`${sessions.length} sessions: ${minutes} minutes`);

Output

2 sessions: 35 minutes

Put it into practice

  1. Predict each result before running the example.
  2. Complete the coding task, then explain why your solution works.

Try it yourself

Code runs on this device. When you are signed in, drafts sync to your account.

Finish the plan summary

Count only unfinished sessions and total their minutes. Display "2 sessions: 35 minutes".

Practice