Access over 20 million homework & study documents

5 Complete the JavaScript function called chkBday which accepts thr

Content type
User Generated
Rating
Showing Page:
1/3
5. Complete the JavaScript function called chkBday which
accepts three parameters. The first is the number of a
month. The second is a day of the month and the third is a
year. If the month is numeric and between 1 and 12, the
day is numeric and between 1 and 31 and the year is
numeric and between 1880 and 2005 then chkBDay returns
true. else chkBDay displays an alert box saying \"Invalid
Birthday\" and returns false. (4 points)
function chkBDay(month, day, year) {
}//end chkBDay
Solution
We will use isNaN() function to determine whether a
supplied value is numeric or not. This function returns true
if value is not a numeric number. For example
calling isNaN(\"A\") returns true
calling isNaN(\"123\") returns false
function chkBDay(month, day, year) {
if(isNaN(month) || isNaN(month) || isNaN(month) || month
< 1 || month > 12 || day < 1 || day > 31 || year < 1880 ||
year > 2005) //if month, year, date is not a number or
doesn\'t belong to permitted range then return false
return false;

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/3
else
return true;
}//end chkBDay
Save below as a .html file then open it using a browser, It
will help you to understand the script better.
<!DOCTYPE html>
<html>
<body>
Click on each button to see the result. <br><br>
<button
onclick=\"chkBDay(\'1\',\'4\',\'2003\')\">chkBDay(\'1\',\'4\',\'
2003\')</button>
True. All values are integer and within range<br><br>
<button
onclick=\"chkBDay(\'1\',\'4\',\'2010\')\">chkBDay(\'1\',\'4\',\'
2010\')</button>
False. Year out of range. Max value allowed is
2005<br><br>
<button
onclick=\"chkBDay(\'A\',\'4\',\'2010\')\">chkBDay(\'A\',\'4\',\'
2010\')</button>
False. Month is \'A\' which is not an integer<br><br>
<button
onclick=\"chkBDay(\'1\',\'32\',\'2000\')\">chkBDay(\'1\',\'32\'
,\'2010\')</button>

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/3

Sign up to view the full document!

lock_open Sign Up
Unformatted Attachment Preview
5. Complete the JavaScript function called chkBday which accepts three parameters. The first is the number of a month. The second is a day of the month and the third is a year. If the month is numeric and between 1 and 12, the day is numeric and between 1 and 31 and the year is numeric and between 1880 and 2005 then chkBDay returns true. else chkBDay displays an alert box saying \"Invalid Birthday\" and returns false. (4 points) function chkBDay(month, day, year) { }//end chkBDay Solution We will use isNaN() function to determine whether a supplied value is numeric or not. This function returns true if value is not a numeric number. For example calling isNaN(\"A\") returns true calling isNaN(\"123\") returns false function chkBDay(month, day, year) { if(isNaN(month) || isNaN(month) || isNaN(month) || month < 1 || month > 12 || day < 1 || day > 31 || year < 1880 || year > 2005) //if mon ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Anonymous
Really helpful material, saved me a great deal of time.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4