HTML and CSS Reference
In-Depth Information
Table 10-26 Code for Reconstructing the Formatted Output and Returning the Formatted Value
var cents = formatAmt[1]
var formatValue=”$”+dollars+”.”+cents
return formatValue
Line 96 assigns two decimal values to the cents variable from the formatAmt[1]
array. Line 97 reconstructs the values, concatenating a dollar sign ($), the dollars, a
decimal point, and the cents. Line 98 returns the formatted value to the CalcLoanAmt()
function. Line 99 closes the function.
To Reconstruct the Formatted Output and Return the Formatted Value
The following step reconstructs the formatted output and returns the formatted value to the calling function.
If necessary, click
line 96.
code entered to reconstruct
output with dollar sign and
decimal value and return result
Enter the JavaScript
code from Table 10-26,
indenting as shown to
reconstruct the format-
ted output and return
the formatted value,
and then press the
e n t e r key (Figure 10-31).
closes function
Figure 10-31
To Pass the Monthly Payment Value to the dollarFormat() Function
To have the monthly payment value appear in the Monthly Payment text field formatted as currency, it
must be passed to the dollarFormat() function. Because the dollarFormat() function manipulates a string value,
the monthly payment result must first be converted to a string using the toString() method. In Chapter 9, the
toString() method was used to convert a date value to a string. In this chapter, the toString() method is used to
convert the monthly payment to a string that the dollarFormat() function can manipulate.
The following step enters the JavaScript statements needed to pass the monthly payment as a string object to
the dollarFormat() function.
Scroll up to and click line 62 (the line that starts with home LoanForm.Payment.value).
Position the insertion point before monthlyPmtAmt.toString(), then type
dollarFormat( without a space.
Position the
insertion point
after dollarFormat
toString() and type )
but do not press
the e n t e r key
(Figure 10-32).
do not press e n t e r key
modify line 62 to pass
monthly payment value
as string to dollarFormat()
user-defined function
Figure 10-32
Search WWH ::

Custom Search