---
id: 6a22d77ddf034bc4e35b1d5a
title: "Challenge 353: Contrast Rating 2"
challengeType: 28
dashedName: 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"`.

```js
assert.equal(getContrastRating(1.0, 0.0, false), "AAA");
```

`getContrastRating(0.9015, 0.1364, false)` should return `"AA"`.

```js
assert.equal(getContrastRating(0.9015, 0.1364, false), "AA");
```

`getContrastRating(0.8965, 0.1628, false)` should return `"Fail"`.

```js
assert.equal(getContrastRating(0.8965, 0.1628, false), "Fail");
```

`getContrastRating(0.7469, 0.0957, true)` should return `"AAA"`.

```js
assert.equal(getContrastRating(0.7469, 0.0957, true), "AAA");
```

`getContrastRating(0.7489, 0.2018, true)` should return `"AA"`.

```js
assert.equal(getContrastRating(0.7489, 0.2018, true), "AA");
```

`getContrastRating(0.6571, 0.1974, true)` should return `"Fail"`.

```js
assert.equal(getContrastRating(0.6571, 0.1974, true), "Fail");
```

# --seed--

## --seed-contents--

```js
function getContrastRating(l1, l2, isLargeText) {

  return l1;
}
```

# --solutions--

```js
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";
}
```
