亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我正在嘗試從表格中將我的總數加在一起,但不知道如何去做

我正在嘗試從表格中將我的總數加在一起,但不知道如何去做

汪汪一只貓 2023-01-06 09:36:41
我正在嘗試從這段代碼中將我的總數加在一起,但不知道該怎么做。這是我一直在研究的腳本,他們每天賺的錢都會翻倍。<script>    // asks for the days you worked    var daysworked = parseFloat(prompt("daysworked", "100"));//equation and table for the days worked    for (var days = 1; days <= daysworked; days++) {        document.write("<tr><td>"+ days +"</td>");        // here is specifically the equation and how i output it         document.write("<td>" + "$" + ( Math.pow(2 , days - 1)*0.01) +"</td></tr>");我應該如何計算賺取的總金額?
查看完整描述

1 回答

?
DIEA

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>");



查看完整回答
反對 回復 2023-01-06
  • 1 回答
  • 0 關注
  • 130 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號