Command Palette

Search for a command to run...

Hectal
Phase 10: Colour, Typography and Responsive Charts
Data Visualization · Exercise 2 of 4 PreviousNext
Intermediate

Compute a WCAG contrast ratio

Write contrast(a, b) so it returns the WCAG contrast ratio of two hex colours: relative luminance is 0.2126 R + 0.7152 G + 0.0722 B of the linear channels (v / 12.92 if v <= 0.04045, else ((v + 0.055) / 1.055) ** 2.4, with v from 0 to 1), and the ratio is (lighter + 0.05) / (darker + 0.05).

The page shows black on white (21.00) and #767676 on white (4.54). The starter always returns 1.

What Check tests

  1. Black on white is 21.00
  2. #767676 on white is 4.54

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.