Skip to content

Instantly share code, notes, and snippets.

@ilovelili
Created October 1, 2020 14:35
Show Gist options
  • Save ilovelili/4123171991114b5cb9dba5208b062b99 to your computer and use it in GitHub Desktop.
Save ilovelili/4123171991114b5cb9dba5208b062b99 to your computer and use it in GitHub Desktop.
<html>
<body>
<script>
function leapYear(year) {
return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
}
function checkDaysinMonth(month) {
const year = new Date().getFullYear();
switch (month) {
case 1:
return 31;
case 2:
return leapYear(year) ? 29 : 28;
case 3:
return 31;
case 5:
return 31;
case 7:
return 31;
case 8:
return 31;
case 10:
return 31;
case 12:
return 31;
default:
return 30;
}
}
alert(checkDaysinMonth(5));
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment