STUDY/JavaScript

JavaScript | [CodeWars] Quarter of the year

Hanee_ 2022. 1. 11. 13:36

# 문제 상황

Given a month as an integer from 1 to 12, return to which quarter of the year it belongs as an integer number.

For example: month 2 (February), is part of the first quarter; month 6 (June), is part of the second quarter; and month 11 (November), is part of the fourth quarter.

 

# 답안

 

const quarterOf = (month) => {
    // Your code here
    if(month <= 3) return 1
    else if(month <=6 ) return 2;
    else if(month <= 9) return 3;
    else return 4;
}

 

# 실행 결과