DEV Community

loading...
Cover image for Day 4 of JavaScriptmas - Century From Year Solution

Day 4 of JavaScriptmas - Century From Year Solution

Sekti
Keep moving forward. Learn well not learn fast.
Updated on ・1 min read

Day 4 is to calculate a century based on the value of year.

For instance year 1700 will be 17 centuries. And 1905 will be 20 centuries.

There is JavaScript solution

function centuryFromYear(num) {

    let modulo = (num % 100 === 0) ? 0 : 1;
    let centuries = Math.floor(num / 100);

    return modulo + centuries;
}
Enter fullscreen mode Exit fullscreen mode

Discussion (0)