```
function endofmonth(input) {
var daysDays0 = 28;
var daysDays1 = 29;
var daysDays2 = 30;
var daysDays3 = 31;
var str = "11-12-1959";
var res = str.split(" ");
//prompt("str");
//alert("str");
dDate = res[0];
mMonth = res[1];
yYear = res[2] + 60;
mathsdDate = dDate;
mathsmMonth = mMonth;
mathsyYear = yYear;
leapyearornot = "no"
leapyear = mathsyYear % 400;
if (leapyear == 0) {
leapyearornot = "yes"
} else {
leapyear = mathsyYear % 100
}
if (leapyear == 0) {
leapyearornot = "yes"
} else {
leapyear = mathsyYear % 4
}
if (leapyear == 0) {
leapyearornot = "yes"
} else {
//
}
if (mathsdDate == 1) {
lastmonthornot = "yes"
} else {
//
}
if (mathsdDate > 1) {
lastmonthornot = "no"
} else {
//
}
resultYear = mathsyYear;
if(mathsdDate == 1 && mathsmMonth == 1){
resultYear = mathsyYear - 1;
}
resultMonth = mathsmMonth
if ( mathsdDate == 1 ); {
resultMonth = mathsmMonth - 1
}
if ( resultMonth == 0 ); {
resultMonth = 12
}
if ( resultMonth == 1 || resultMonth == 3 || resultMonth == 5 || resultMonth == 7 || resultMonth == 8 || resultMonth == 10 || resultMonth == 12 ); {
resultDate = "31"
}
if ( resultMonth == 4 || resultMonth == 6 || resultMonth == 9 || resultMonth == 11 ); {
resultDate = "30"
}
if ( resultMonth == 2 && leapyearornot == "yes" ); {
resultDate = "29"
}
if ( resultMonth == 2 && leapyearornot == "no" ); {
resultDate = "28"
}
if ( resultMonth < 10 ) ; {
endofmonth = resultDate + "-0" + resultMonth + "-" + resultYear
}
if ( resultMonth > 9 ) ; {
endofmonth = resultDate & "-" & resultMonth & "-" & resultYear
}
return endofmonth;
}
```

Could someone please look into this code.

Thanks.