← Back to challenges

Convert Year to Century

JavaScriptHardalgorithmsdatesmath

Instructions

Write a function that takes a year and returns its corresponding century.

Examples

centuryFromYear(2005) ➞ 21

centuryFromYear(1950) ➞ 20

centuryFromYear(1900) ➞ 19

Notes

For guidance on the year boundaries for each century:

  • The 19th century are the years from 1801 to 1900.
  • The 20th century are the years from 1901 to 2000.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Filter a String