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
- 3000x2000 with max 1024 gives 1024x683
- A small image is not enlarged
- A portrait photo is scaled by its height
- 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.