Problem
We are required to write a JavaScript function that takes in a number that represents a year and find the century that year falls in.
For instance,
1864 falls in the 19th century.
2021 falls in the 21st century.
Example
Following is the code −
const year = 1956; const findCentury = (year) => { let century = 0; for(let i = 0; i < year; i++){ if(i % 100 === 0){ century++; }; }; return century; }; console.log(findCentury(year));
Output
Following is the console output −
20