All challenges

TypeScript · easy

Maybe null

#20

Situation

CMS preview crashes when the page is missing, while an intentionally blank heading is replaced with "Untitled". pageTitle needs to distinguish a missing page from an empty heading.

Objective

Return "Untitled" only when the page is missing, and preserve an empty heading when the page exists. pageTitle(null)"Untitled"; pageTitle({ heading: "" })""; pageTitle({ heading: "Hi" })"Hi".

The repo at start

workspace/
└── src/
    └── title.ts   (page can be null; empty heading is legal)

Checks you will turn green

  • exports pageTitle
  • null page is Untitled
  • empty heading stays empty
  • heading Hi returns Hi

Concepts

nullishoptional

Play it in your terminal

With sharpen installed, this command opens exactly this challenge in your local arena:

sharpen 20

First time? The full install is right below.

How to play

  1. 1 Install Claude Code if you do not have it yet: claude.com/claude-code
  2. 2 Install sharpen from npm:
    npm install -g @juanwmedia/sharpen
  3. 3 Then launch it; the arena opens in your browser:
    sharpen 20
  4. or Or try it without installing anything:
    npx @juanwmedia/sharpen 20
  5. 4 And to update when a new version ships:
    sharpen update