The Task
The first century spans from the year 1 up to and including the year 100, the second century - from the year 101 up to and including the year 200, etc.
Given a year, return the century it is in. However, for the else if block, its returning 19.64
, rather than 20
. What is the issue with this line?
const onCenturyCrossover = function (year) {
return year % 2 === 0;
};
const century = function (year) {
if (onCenturyCrossover(year) === true) {
return year / 100;
} else if (onCenturyCrossover(year) === false) {
return Math.trunc(year / 100) 1;
}
};
console.log(century(2000));
console.log(century(1964));
CodePudding user response:
const century = year => Math.floor(year/100) 1;