Question: Need help with Murach's Javascript and JQuery short 14-2 use strict; $(document).ready(function() { var calculateDays = function( date ) { var today = new Date();

Need help with Murach's Javascript and JQuery short 14-2

"use strict"; $(document).ready(function() { var calculateDays = function( date ) { var today = new Date(); var oneDay = 24*60*60*1000; // hours * minutes * seconds * milliseconds var days = ( date.getTime() - today.getTime() ) / oneDay; return Math.ceil(days); }; $("#countdown").click(function() { var event = $("#event").val(); var dt = $("#date").val(); var message = $("#message"); var date, days;

// clear previous message message.text( " " );

//make sure task and due date are entered and correct if (event.length === 0 || dt.length === 0) { message.text( "Please enter both a name and a date." ); } else { //make sure due date string has slashes and a 4-digit year var index = dt.indexOf("/"); if (index === -1) { message.text( "Please enter the date in MM/DD/YYYY format." ); } else { // check for the second slash if (dt.indexOf("/", index + 1) === -1) { message.text( "Please enter the date in MM/DD/YYYY format." ); } }

var year = dt.substring(dt.length - 4); if (isNaN(year)) { message.text( "Please enter the date in MM/DD/YYYY format." ); }

//convert due date string to Date object and make sure date is valid date = new Date(dt); if (date === "Invalid Date") { message.text( "Please enter the date in MM/DD/YYYY format." ); } }

// if no error messages, calculate and display days until event if (message.text() === " ") {

//calculate days days = calculateDays(date);

//create and display message if (days === 0) { message.text( "Hooray! Today is " + event + "!" ); } if (days 0) { message.text( days + " day(s) until " + event + "!" ); } } }); // end click() // set focus on initial page load $("#event").focus(); }); // end ready()

Need help with Murach's Javascript and JQuery short 14-2 "use strict"; $(document).ready(function()

{ var calculateDays = function( date ) { var today = new

E D Pageview | A Read aloud D Short 14-2 Add exception handling to the Countdown application In this exercise, you'll add exception handling to the Countdown application to make sure an argument is passed to a function. When you're done, the Countdown application will display a custom error message if the argument isn't sent (see below). Estimated time: 20 to 30 minutes. Countdown To... Event Name: Christmas Event Date: 12/25/2017 Countdown ReferenceError: The calculateDays function requires a date parameter. 1. Open the HTML and JavaScript files in this folder sol_shortc24\countdown 2. In the main JavaScript file, comment out the call to the calculateDays function. Then, code a new call that passes no arguments to the function. Now, run the application and see that nothing happens 3. Open the Console panel and view the error message there. "Cannot read property 'getTime' of undefined". Note that this error message gives you information about the problem, but you'll still need to do some work to track down what's wrong 4. In the JavaScript file, modify the calculateDays function so it makes sure the value of the date" parameter ist andetined If it isn't the function should be done. Otherwise, this function should create and throw an error object with the custom these shown above 5 Ram the application again and then view the or message in the Come nel. This time, the error mense explains exactly what is wrong o Countdown ReferenceError: The calculateDays function requires a date parameter. 1. Open the HTML and JavaScript files in this folder: exercises_short\ch14\countdown 2. In the main JavaScript file, comment out the call to the calculateDays function. Then, code a new call that passes no arguments to the function. Now, nun the application and see that nothing happens. 3. Open the Console panel and view the error message there - "Cannot read property 'getTime' of undefined". Note that this error message gives you information about the problem, but you'll still need to do some work to track down what's wrong. 4. In the JavaScript file, modify the calculate Days function so it makes sure the value of the "date" parameter isn't undefined. If it isn't the function should be done. Otherwise, this function should create and throw an error object with the custom message shown above. 5. Run the application again and then view the error message in the Console panel. This time, the error message explains exactly what is wrong. 6. Put the call to the calculateDays function and the if statements that follow it inside a try-catch statement. In the catch block of the statement, display the custom crror message in the span tag whose id is "message". Run the application and view the error message in the page. . Fix the application so the call to the calculateDay function passes the date as an argument like it originally did O 3

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!