我们需要编写一个JavaScript函数,该函数接受从1开始的月份索引,并返回该月份所在的季度。
以下是代码-
const month = 7;
const findQuarter = (month = 1) => {
   if (month <= 3) {
      return 1
   } else if (month <= 6) {
      return 2
   } else if (month <= 9) {
      return 3
   } else if (month <= 12) {
      return 4
   }
}
console.log(findQuarter(month));输出结果以下是控制台输出-
3