Question #59141

Write a program called dayofmonth.js that displays how many days are in the month for a given month and year. Use 2 (February) for the month and 2000 for the year.

See Sample Execution Below:

This program will determine the number of days in a given month.

Month (1-12) : 2

Year: 2000

There are 29 days in the month

Expert's answer

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/

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS