Command Palette

Search for a command to run...

Hectal
Phase 4: Strings, Numbers and Dates
JavaScript · Exercise 3 of 5 PreviousNext
Beginner

Read log lines with a regex

A server writes lines like [2024-01-15 10:30] ERROR: Disk full.

Write parseLog(line) that returns an object { date, time, level, message } (all strings) for a valid line, and null for anything else. The message can itself contain colons.

The page code then lists only the ERROR lines in #errors, as 10:30 — Disk full. That part is already written; it starts working once parseLog does.

What Check tests

  1. A valid line is split into date, time, level and message
  2. Colons inside the message are kept
  3. A line in the wrong shape gives null
  4. The page lists the two errors

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.