Answer on Question #59141 Programming & Computer Science / AJAX |
JavaScript | HTML | PHP | for completion.
The algorithm of the program is following:
1. Enter the data – month & year.
2. Check if month = 2:
a. If true – check if year is divided by 4, then the month has 29 days.
b. Otherwise – 28 days.
3. If month does not equal 2:
a. Check if the month is even – it has 30 days.
b. Otherwise – 31 days.
HTML code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>DayOfMonth</title>
<script src="dayofmonth.js"></script>
</head>
<body>
</body>
</html>JavaScript code:
var month = +prompt("Month(1-12):");
var year = +prompt("Enter a year:");
console.log('Month(1-12): ', month);
console.log('Year: ', year);
if(month === 2){
if(year % 4 === 0){
console.log('There are ' + 29 + ' days in the month.');
}else{
console.log('There are ' + 28 + ' days in the month.');
}
}else{
if (month % 2 === 0) {
console.log('There are ' + 30 + ' days in the month');
}else{
console.log('There are ' + 31 + ' days in the month');
}
}http://www.AssignmentExpert.com/