dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
1.9 KiB
1.9 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 6a22d77ddf034bc4e35b1d5a | Challenge 353: Contrast Rating 2 | 28 | challenge-353 |
--description--
Given two relative luminance values and a boolean indicating whether the text is large, return the WCAG contrast rating using the following method:
Calculate the contrast ratio by adding 0.05 to each luminance value, then dividing the lighter one by the darker one. The lighter one will always be the first argument.
Return the rating based on the contrast ratio using the following table:
| Rating | Normal Text | Large Text |
|---|---|---|
"AAA" |
7.0+ | 4.5+ |
"AA" |
4.5+ | 3.0+ |
"Fail" |
below 4.5 | below 3.0 |
--hints--
getContrastRating(1.0, 0.0, false) should return "AAA".
assert.equal(getContrastRating(1.0, 0.0, false), "AAA");
getContrastRating(0.9015, 0.1364, false) should return "AA".
assert.equal(getContrastRating(0.9015, 0.1364, false), "AA");
getContrastRating(0.8965, 0.1628, false) should return "Fail".
assert.equal(getContrastRating(0.8965, 0.1628, false), "Fail");
getContrastRating(0.7469, 0.0957, true) should return "AAA".
assert.equal(getContrastRating(0.7469, 0.0957, true), "AAA");
getContrastRating(0.7489, 0.2018, true) should return "AA".
assert.equal(getContrastRating(0.7489, 0.2018, true), "AA");
getContrastRating(0.6571, 0.1974, true) should return "Fail".
assert.equal(getContrastRating(0.6571, 0.1974, true), "Fail");
--seed--
--seed-contents--
function getContrastRating(l1, l2, isLargeText) {
return l1;
}
--solutions--
function getContrastRating(l1, l2, isLargeText) {
const ratio = (l1 + 0.05) / (l2 + 0.05);
if (isLargeText) {
if (ratio >= 4.5) return "AAA";
if (ratio >= 3.0) return "AA";
} else {
if (ratio >= 7.0) return "AAA";
if (ratio >= 4.5) return "AA";
}
return "Fail";
}