The Carpet House owner wants to put a carpet calculator on his website so that v
ID: 3552559 • Letter: T
Question
The Carpet House owner wants to put a carpet calculator on his website so that visitors can estimate the amount of carpet they will need to purchase. A form named carpet is used to collect the length and width values, and to display the value of the calculated square feet. A 15% allowance is typically included for room irregularities and unavoidable waste. Complete the code for the following function to provide that functionality. function ComputeSquareFeet( ) { /* get the values for length and width */ /* set the value for the overage */ /* compute the correct number of square feet needed */ /* set the value of the appropriate form input element to display the calculated total*/ }Explanation / Answer
<html>
<head>
<title>Simple Javascript Calculator - Carpenter Application</title>
<script language="javascript" type="text/javascript">
function computeSquareFeet()
{
a=Number(document.calculator.length.value);
b=Number(document.calculator.width.value);
c=a*b*1.5;
document.calculator.total.value=c;
}
</script>
</head>
<body>
<!-- Opening a HTML Form. -->
<form name="calculator">
<!-- Here user will enter length -->
Number 1: <input type="text" name="length">
<!-- Here user will enter width -->
Number 2: <input type="text" name="width">
<!-- Here result will be displayed. -->
Get Result: <input type="text" name="totalCost">
<!-- Here respective button when clicked, calls only respective function. -->
<input type="button" value="Calculate">
</form>
</body>
</html>