JSFiddle - React, Tailwind, and code Playground

HTML

<label>month</label>
<input type="text" id="month"></input>
<label>year</label>
<input type="text" id="year"></input>
<button id="calculateDays">calculate days</button>

JavaScript

function getDaysInMonth(m, y)
{
    // months in JavaScript start at 0 so decrement by 1 e.g. 11 = Dec
    --m;

    // if month is Sept, Apr, Jun, Nov return 30 days
    if( /8|3|5|10/.test( m ) ) return 30;

    // if month is not Feb return 31 days
    if( m != 1 ) return 31;

    // To get this far month must be Feb ( 1 )
    // if the year is a leap year then Feb has 29 days
    if( ( y % 4 == 0 && y % 100 != 0 ) || y % 400 == 0 ) return 29;

    // Not a leap year. Feb has 28 days.
    return 28;
}
document.getElementById("calculateDays").onclick = function() {
    console.log( 
        getDaysInMonth( 
            document.getElementById( "month" ).value,
            document.getElementById( "year" ).value
        )
    );
}