I have been struggling to format the date as follows:
"Today is Sunday, the 31st day of March in the year 2019."
I am working with JavaScript in an HTML5 document. Below is the code I have so far, and I would appreciate any help. I prefer not to rely on any third-party libraries, only using basic JavaScript.
<script type="text/javascript>
var monthName = new Array();
monthName[0] = "January";
monthName[1] = "February";
monthName[2] = "March";
monthName[3] = "April";
monthName[4] = "May";
monthName[5] = "June";
monthName[6] = "July";
monthName[7] = "August";
monthName[8] = "September";
monthName[9] = "October";
monthName[10] = "November";
monthName[11] = "December";
var myYear = today.getFullYear();
var myDate = today.getDate();
var dayExt = "th";
if ((myDate == 1) || (myDate == 21) || (myDate == 31)) dayExt = "st";
if ((myDate == 2) || (myDate == 22)) dayExt = "nd";
if ((myDate == 3) || (myDate == 23)) dayExt = "rd";
var extDate = myDate + dayExt;
document.write(extDate + "Today is the day of ");
document.write(monthName[today.getMonth()] + " in the year ");
document.write(myYear + ".");
</script>
Current output: No result
Expected output: Today is Sunday, the 31st day of March in the year 2019.