0 of 6 problems solved0%
1 of 6

Profile Card

Interfaces are helpful when you pass objects around. An optional property may be missing. A readonly property can’t be changed after it’s set. You will model a small profile and create a short label string from it.

interface Movie {
  readonly id: number;
  title: string;
  year?: number;
}

Keep the logic simple and do not change the input object.

Your Task

Create a profile interface and format a label.

  • Define interface Profile with readonly id: number, name: string, age?: number.
  • Write function formatProfile(p: Profile): string.
  • If age exists, return "<name> (<age>) [id:<id>]".
  • Otherwise return "<name> (unknown) [id:<id>]".
  • Do not mutate the input.