So, I have a problem where I have to return the century. I have made a code but it fails for years like 1700 or 1800. My question is, how can I make a special case that if the year is fixed, like 2000 it only divides the year by 100? I have tried with
element.slice(-2);
but it didn't work. Here's my current code
function centuryFromYear(year) {
var x = Math.floor(year/100) + 1;
return x;
}