function getMonth(input){
if(input.length > 0 && (input >= 1 && input <= 12)){
let months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
printResult(months[input - 1], true);
} else {
printResult('Your input should be a number between 1 and 12.', false);
}
}
function printResult(output, success){
document.getElementById("result").style.color = "red";
document.getElementById('result').innerHTML = output;
if(success){
document.getElementById("result").style.color = "green";
}
}
<html>
<body>
<div>
<input id="month-user-input" type="number" />
<p id="result">Waiting for user input</p>
<button id="btn-get-month" onclick="getMonth(document.getElementById('month-user-input').value)">check</button>
</div>
</body>
</html>