Command Palette

Search for a command to run...

Hectal
Phase 11: Files, Images and Voice
AI Frontend · Exercise 2 of 5 PreviousNext
Beginner

Work Out the Shrunk Size

Before sending a photo, Mitra shrinks it so its longest side is at most max pixels. Write fitWithin(w, h, max) that returns { w, h }. Keep the shape (scale both sides by the same factor), round to whole pixels, never enlarge a small image, and never return less than 1 pixel.

The page reads the three number boxes when #calc is clicked and shows <w>x<h> in #out.

What Check tests

  1. 3000x2000 with max 1024 gives 1024x683
  2. A small image is not enlarged
  3. A portrait photo is scaled by its height
  4. A very thin strip never gets a side of 0

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.