DEV Community

Cover image for Day 4 of JavaScriptmas - Century From Year Solution
Sekti Wicaksono
Sekti Wicaksono

Posted on • Edited on

Day 4 of JavaScriptmas - Century From Year Solution

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

Top comments (0)