How many days in the month?
- O(1) · Trivial
- Free
- Python
- JavaScript
- lists
- conditionals
Problem
Write a function that takes the number of the month (1 is January, 12 is December) and whether the year is a leap year (true or false), and returns how many days that month has.
April, June, September and November have 30 days, the rest have 31. February is the odd one: 28, or 29 when the year is a leap year.
Examples
January
1, false → 31
June
6, false → 30
A plain February
2, false → 28
Besides these, the challenge has hidden tests that are revealed when you submit your solution.
You start with this
Python
def days_in_month(month, leap):
passJavaScript
function daysInMonth(month, leap) {
}Solve this challenge
It opens in your browser, with the editor and the tests. It is free and you do not need an account to start.