Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Part B: Implement JavaScript Declare variables. Create the Date object named Tod

ID: 3668002 • Letter: P

Question

Part B: Implement JavaScript

Declare variables.

Create the Date object named Today.

Create the variable ThisDay and assign it the current day.

Create the variable ThisMonth and assign it the current month.

Create the variable this year and assign it the current year.

Create the variable DaysLeft. Use the NYEDays function to obtain this value. Send the Today Date object as the argument.

Create the array MonthTxt with 13 locations. The first location( 0) should have the a blank “ “ value. The remaining locations should have the name of the months (“January”, “February”, …… “December”).

Output and Decisions

Display the current date.

Using an if/else statement, determine and display the number of days until New Year’s Eve.

Save the file to your local computer.

Explanation / Answer

<!DOCTYPE html>
<html>
<body>

<p id="demo"></p>

<script>

function NYEDays(CheckDay) {
var XYear=CheckDay.getFullYear();
var XDay=new Date("December, 31, 2015");
XDay.setFullYear(XYear);
var DayCount=(XDay-CheckDay)/(1000*60*60*24);
DayCount=Math.round(DayCount);
return DayCount;
}

var Today = new Date();
var ThisDay = Today.getDay();
var ThisMonth = Today.getMonth();
var ThisYear = Today.getYear();
var DaysLeft = NYEDays(Today);
var MonthTxt = [" ", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
document.writeln("Today's date is " + Today.getDate());
document.writeln(" Number of days until newyear's eve is: " + DaysLeft);
</script>

</body>
</html>