2 回答
TA贡献1806条经验 获得超5个赞
我只是添加Math.pow
并且它有效,错误就在那里。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="Cersoy-CNIT133-Assignments-4-part2" content="Cersoy-CNIT133-Assignments-4part2">
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link href="../Assignment_all.css" type="text/css" rel="stylesheet">
<title>Cersoy-CNIT133-Assignments_4-Part2</title>
<style>
#main{
background-color: rgb(222, 209, 135);
margin: auto;
height: 30%;
width: 50%;
padding: 1em;
text-align: center;
border-radius: 10px;
}
table{
margin: auto;
width: 50%;
}
th{
border: solid 1px black;
background-color: maroon;
color: white;
}
td{
border: solid 1px black;
background-color: rgb(201, 255, 4);
color: blue;
}
</style>
</head>
<body>
<header>
Cersoy-CNIT133-Assignments 4-Part2
</header>
<div id="main">
<table id="table1" >
<tr>
<th>Year</th>
<th>Amount of deposit</th>
<th>Intrest Rate</th>
</tr>
</table>
<table id="table2" >
<tr>
<th>Year</th>
<th>Amount of deposit</th>
<th>Intrest Rate</th>
</tr>
</table>
<table id="table3" >
<tr>
<th>Year</th>
<th>Amount of deposit</th>
<th>Intrest Rate</th>
</tr>
</table>
<script>
var rate1=5;rate2=6;rate3=7;
function addRow(a,b,c,t) {
var table=0;
if(t==1){table = document.getElementById("table1");}
if(t==2){
table = document.getElementById("table2");
}
else if(t==3){
table = document.getElementById("table3");
}
var row = table.insertRow(-1);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
cell1.innerHTML = a;
cell2.innerHTML = b;
cell3.innerHTML = c;
}
function calc(rate,tab){
var P=1000,A=0,n=0;
r=rate.toFixed(2)
r=r/100;
for(n=1;n<=10;n++){
A=(P*(Math.pow((1+r),n)));
var fn,o;
o = {style: "currency", currency: "USD",minimumFractionDigits: 2,maximumFractionDigits: 2};
fn = A.toLocaleString("en", o);
addRow(n,fn,r,tab);
P=A;
}
}
document.addEventListener("DOMContentLoaded",calc(rate1,"1") +calc(rate2,"2")+calc(rate3,"3"));
</script>
</div>
<form action="hm4.html">
<button class="back_button" >Return to Assignment-4 page</button>
</form>
<footer>
This Webpage designed by Cagatay Ersoy
</footer>
</body>
</html>
TA贡献2003条经验 获得超2个赞
将用于的选项对象更改.toLocalString()为此:
A.toLocaleString(undefined, {
minimumFractionDigits: 2,
maximumFractionDigits: 2
})
您的 HTML 中有几个错误,您也应该考虑修复这些错误。
添加回答
举报