JSFiddle - React, Tailwind, and code Playground

by Rob Lardy

JavaScript

/*
Month names

Write a function that will return the Month name for a given number (1-12). 

You will want to make a closure to close over the array of month names that you will likely need in order to map 1-12 to a name. So because of this the function should RETURN another function (this is key to the closure). 

*/

var MonthName = function(i){
    
    var montharray = ["January", "February", "March", "April", "May", "June","July" ];
  
    return montharray[i];
    
}

console.log(MonthName(2));
// → March