Files
wehub-resource-sync 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
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

81 lines
1.5 KiB
Markdown

---
id: 6a22d77ddf034bc4e35b1d59
title: "Challenge 352: Contrast Rating 1"
challengeType: 28
dashedName: challenge-352
---
# --description--
Given a contrast ratio and a boolean indicating whether the text is large, return the WCAG rating 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("7.5", false)` should return `"AAA"`.
```js
assert.equal(getContrastRating("7.5", false), "AAA");
```
`getContrastRating("4.8", false)` should return `"AA"`.
```js
assert.equal(getContrastRating("4.8", false), "AA");
```
`getContrastRating("4.2", false)` should return `"Fail"`.
```js
assert.equal(getContrastRating("4.2", false), "Fail");
```
`getContrastRating("4.5", true)` should return `"AAA"`.
```js
assert.equal(getContrastRating("4.5", true), "AAA");
```
`getContrastRating("3.0", true)` should return `"AA"`.
```js
assert.equal(getContrastRating("3.0", true), "AA");
```
`getContrastRating("2.7", false)` should return `"Fail"`.
```js
assert.equal(getContrastRating("2.7", false), "Fail");
```
# --seed--
## --seed-contents--
```js
function getContrastRating(ratio, isLargeText) {
return ratio;
}
```
# --solutions--
```js
function getContrastRating(ratio, isLargeText) {
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";
}
```