Module 5 · In Studio · challenge 2 of 2 in this lesson

challenges/work/ui_design.luau exports contrastRatio(a, b), toScale(px, framePx) and passes(ratio, textPx, bold)

A test in Studio grades it and prints a pass code.

Open

Level 3, Professional

Challenge

Write the three functions in challenges/work/ui_design.luau in the game repo (start from the m14-ship tag to get challenges/work/ui_design.luau and challenges/ui-design.luau). The test checks them against the shop's real colours, including the Coin Pack at UIScale 0.65. The written solution is challenges/solutions/ui-design.md.

Start from
The game at milestone m14 (download)
Grade it
In Studio, press Play, then run game.ServerScriptService.RunGameTests:Invoke("ui-design", "ui-design-contrast") in the server command bar. Copy the pass code from Output.

Done means

  • challenges/work/ui_design.luau exports contrastRatio(a, b), toScale(px, framePx) and passes(ratio, textPx, bold)
  • contrastRatio computes the WCAG contrast ratio of two RGB colours
  • toScale converts a Figma pixel size to a UDim2 scale rounded to 3 decimal places (math.round(px / framePx * 1000) / 1000)
  • passes returns whether a contrast ratio meets WCAG AA for the given text pixel size and bold flag
  • challenges/ui-design.luau prints TEST PASS for every check

The Course Runner prints this code when the test passes.