这个是要求
以下是我的代码,请指出哪里需要怎么修改,感激万分
这个是HTML代码
<html>
<title>Made By WONG_ZiF</title>
<head><h2>Welcome to interest rate calculator</h2></head>
<body>
<form name = "calculator">
<table>
<tr>
<td>Principal(HKD) :</td>
<td><input type="text" name="principal" value=''></td>
</tr>
<tr>
<td>Interest Rate(%) :</td>
<td><input type="text" name="rate" value=''></td>
</tr>
<tr>
<td><input type="radio" name="selectRate" value="simple">Simple Rate</td>
<td><input type="radio" name="selectRate" value="compound">Compound Rate</td>
</tr>
<tr>
<td>Number of Years :</td>
<td><input type ="text" name="year" value=''></td>
</tr>
<tr>
<td>Interest Amount(HKD) :</td>
<td><input type="text" name="amount" value='' disabled></td>
</tr>
<tr>
<td><input type="button" value="Calculate" onclick="document.calculator.amount.value="calculate()""></td>
<td><input type="reset" value="Reset All"></td>
</tr>
</table>
</form>
</body>
</html>
这个是JavaScript代码
function interest(principal, mode, rate, year){
if(mode == "simple"){
var Sl;
Sl = principal * rate * year;
return Sl;
}else{ // compound interest
var Cl;
Cl = principal * ((1 + rate)**year - 1);
return Cl;
}
}
function twoDP(number) {
var number;
number = Math.round( num * 100 ) / 100;
return number;
}
function calculate(){
var P = parseFloat(document.calculator.principal.value);
var Rt = parseFloat(document.calculator.rate.value);
var N = parseFloat(document.calculator.year.value);
var mode = parseFloat(document.calculator.selectRate.value);
return twoDP(interest(P, mode, Rt, N));
}
这个是最后要呈现的界面