1 回答
TA贡献1820条经验 获得超2个赞
也许这会给你一个提示:
var earningsPerDay = 77;
var totalEarnings = 0;
for (var days = 1; days <= daysworked; days++) {
totalEarnings = totalEarnings + earningsPerDay;
document.write("<tr><td>"+ days +"</td>");
document.write("<td>" + "$" + totalEarnings +"</td></tr>");
}
更新
经过您的解释,这里有一个更好的答案:
var totalEarnings = 0;
for (var days = 1; days <= daysworked; days++) {
todaysEarnings = Math.pow(2 , days - 1) * 0.01;
totalEarnings = totalEarnings + todaysEarnings;
document.write("<tr><td>"+ days +"</td>");
document.write("<td>" + "$" + todaysEarnings +"</td></tr>");
}
document.write("<tr><td>" + "Total: $" + totalEarnings +"</td></tr>");
要么:
document.write("<td>" + "$" + todaysEarnings +"</td><td>" + totalEarnings + "</td></tr>");
添加回答
举报