任務
第一世紀跨度從 1 年到并包括 100 年,第二個世紀 - 從 101 年到并包括 200 年,以此類推。
給定一年,回傳它所在的世紀。但是,對于 else if 塊,它回傳的是19.64,而不是20。這條線有什么問題?
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));
uj5u.com熱心網友回復:
const Century = year => Math.floor(year/100) 1;
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/352339.html
標籤:javascript 算法 功能 截短
