Skip to content
SDETRole
SDETRole

Classify an HTTP status code

beginner Automation utilities Challenge 18 of 18

Write statusClass(code), a small helper for API tests that tells you which class an HTTP status code belongs to.

Requirements

  • Return 'informational' for 100–199, 'success' for 200–299, 'redirection' for 300–399, 'client error' for 400–499 and 'server error' for 500–599.
  • Throw a RangeError when code is not an integer (for example 404.5, NaN or the string '404').
  • Throw a RangeError when code is below 100 or above 599.

Expected output

statusClass(204) → 'success' statusClass(404) → 'client error' statusClass(503) → 'server error' statusClass(600) → throws RangeError

Test cases (6)

  • ○classifies 1xx and 2xx codes, including boundaries
  • ○classifies 3xx and 4xx codes
  • ○classifies 5xx codes up to 599
  • ○throws a RangeError just outside the range (99 and 600)
  • ○throws a RangeError for non-integers
  • ○throws for zero, negative numbers and numeric strings
solution.jsExecutes in your browser

Ctrl/⌘ + Enter to run tests · your code is saved in this browser

Results

Run the tests to see results here.

Type to search across SDETRole.

Full-text search by Pagefind · runs in your browser Open search page →