← Back to challenges

Convert Number to Corresponding Month Name

JavaScriptHardarraysdatesconditionsformatting

Instructions

Create a function that takes a number (from 1 to 12) and returns its corresponding month name as a string. For example, if you're given 3 as input, your function should return "March", because March is the 3rd month.

NumberMonth Name
1January
2February
3March
4April
5May
6June
7July
8August
9September
10October
11November
12December

Examples

monthName(3) ➞ "March"

monthName(12) ➞ "December"

monthName(6) ➞ "June"

Notes

  • You can expect only integers ranging from 1 to 12 as test input.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: After N Months...