Question: Enter the average.html text from Figure 17.12 into a new Web page, then load this page to verify that it behaves as described. What happens
Enter the average.html text from Figure 17.12 into a new Web page, then load this page to verify that it behaves as described. What happens if you click on the button without entering any numbers in the text box?
Calling the split method on an empty string produces an empty array, i.e., an array with length 0. Thus, clicking the button in this page without entering any numbers will result in a call to the Average function with an empty array as input. When the function attempts to calculate the average of an empty array, a division by zero occurs, causing the function to return NaN. Modify the Average function so that it returns 0, rather than NaN, if its input is empty. Then verify that your average.html page displays 0 for the average if the user leaves the text box empty?
Step by Step Solution
3.34 Rating (160 Votes )
There are 3 Steps involved in it
function AveragenumArray Assumes numArray is an array of numbers Returns avera... View full answer
Get step-by-step solutions from verified subject matter experts
Document Format (1 attachment)
1409-C-S-O-S(1171).docx
120 KBs Word File
