Return a month name using a Javascript if statement - Javascript Statement

Javascript examples for Statement:if

Description

Return a month name using a Javascript if statement

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <div id="months">
         unchanged/*from  w  w w. j  a va 2 s .com*/
      </div> 
      <script type="text/javascript">
window.onload = function() {
    var monthName = getMonth(12);
    document.getElementById("months").innerHTML = monthName;
};
function getMonth(month) {
   var monthName;
    if (month === 12) {
        monthName = 'December';
    }
   return monthName;
}

      </script>  
   </body>
</html>

Related Tutorials