The function below calculates the day of the week for any given date, but not working, please help

<html>
<head>

<style type="text/css">

button {
	padding: 2px;
    width: 62px;
    color: black;	
}

#intro {
	width: 55%;
	background-color: #f1f1f1;
	border: 1px solid #000;
	padding:10px;
}

#input {
	width: 55%;
	background-color: #99ccff;
	border: 1px solid #000;
	padding:10px;
}

#result {
	width: 55%;
	background-color: #B3D2A5;
	border: 1px solid #000;
	padding:10px;
}

</style>

<script type="text/javascript">

function getDayName() {

    var myDate= document.getElementById("dateInput").value;
	
	if(myDate == ""){
		document.getElementById("result").innerHTML = "Invalid date. Please enter a date in dd/mm/yyyy fomat"
	}
	else {
		document.getElementById("result").innerHTML = "";
		myDate=myDate.split("/");
		var newDate=myDate[2]+"-"+myDate[1]-1+"-"+myDate[0];
		var currentDate = new Date(newDate);
		var day_name = currentDate.getDay();
		var days = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");

		var months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
		var month_name = currentDate.getMonth();
		var year = myDate[2];

		document.getElementById("result").innerHTML = day_name;
	}
}

</script>

</head>
<body>

<div id="intro">
	The function below calculates the day of the week for any given date. It currently is not returning the correct day.<br><br>

	<strong>Part 1:</strong> The function is not working correctly.  Fix it to return the correct day. <strong>Test cases:</strong> 26/07/1969 = Saturday || 01/06/2020 = Monday.<br><br>
	<strong>Part 2:</strong> Update the function to print the day and month as follows.  <strong>Test cases:</strong> 26/07/1969 = Saturday, 26 July 1969 || 31/12/1999 = Friday, 31 December 1999.<br><br>
</div>
<br>
<div id="input">
	<br>
	<label for="dateInput">Enter date (dd/mm/yyyy)</label>&nbsp;
	<input type="text" id="dateInput" size="15">&nbsp;<button value="find the day" onclick="javascript:getDayName()">submit</button><br><br>
</div>
<br>
<div id="result"></div>

</body>
</html>
  1. You can’t perform subtraction on strings. Look at the newDate assignment where the string concatenation is happening.

  2. You need to use the numbers returned from getDay and getMonth to index into the two arrays with the weekdays and months.

  3. You need to use getDate to get the date for the final string.

  4. Use a template literal or just concatenation to construct the final string.

Thank you so very much.

Would you please write the correction for me please ?

It’s all done.
THANKS HUGE.