第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

我如何從循環(huán)中獲取數(shù)組?

我如何從循環(huán)中獲取數(shù)組?

RISEBY 2023-03-10 16:07:19
大家好,你能幫我計(jì)算步數(shù)嗎?在此處輸入圖像描述function getPlan(currentProduction, months, percent) {  // write code here  let sum = 0;  for(let i = 0; i < months; i++){    let workCalculate = currentProduction * percent / 100;    sum *= workCalculate;  }  return Math.floor(sum);}示例:getPlan(1000, 6, 30) === [1300, 1690, 2197, 2856, 3712, 4825] getPlan(500, 3, 50) === [750, 1125, 1687]
查看完整描述

3 回答

?
隔江千里

TA貢獻(xiàn)1906條經(jīng)驗(yàn) 獲得超10個(gè)贊

只需將每次迭代推送到一個(gè)數(shù)組并返回該數(shù)組。


function getPlan(currentProduction, months, percent) {

  // write code here

  // starting at currentProduction

  let sum = currentProduction;

 

  // output

  let output = [];

  

  for(let i = 0; i < months; i++){

    // progressive from sum and not from currentProduction

    let workCalculate = sum * percent / 100;

  

    sum += Math.floor(workCalculate);

    output.push(sum)

  };

  

  return output

};


console.log(getPlan(1000, 6, 30))

console.log(getPlan(500, 3, 50))


查看完整回答
反對(duì) 回復(fù) 2023-03-10
?
慕慕森

TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超17個(gè)贊

目前你的方法返回一個(gè)數(shù)字,而不是一個(gè)數(shù)組。你到底需要什么?您需要它返回一個(gè)數(shù)組,還是只想查看循環(huán)內(nèi)計(jì)算的中間值?


在第一種情況下,創(chuàng)建一個(gè)空數(shù)組并在循環(huán)的每一步中添加您想要的值:


function getPlan(currentProduction, months, percent) {

  // write code here

  let sum = 0;

  var result= [];


  for(let i = 0; i < months; i++){

    let workCalculate = currentProduction * percent / 100;

    sum *= workCalculate;

    result.push(sum);

  }


  return result;

}

在第二種情況下,您有兩個(gè)選擇:

  • 添加一個(gè)console.log,以便將值打印到控制臺(tái)。

  • 添加一個(gè)斷點(diǎn),以便代碼在該處停止,您可以看到變量的值并逐步執(zhí)行程序。

這有點(diǎn)含糊,因?yàn)槟男枨蟛磺宄?,希望?duì)您有所幫助!


查看完整回答
反對(duì) 回復(fù) 2023-03-10
?
森欄

TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超5個(gè)贊

function getPlan(currentProduction, months, percent) {

  var plan=[];

  var workCalculate=currentProduction;

  

  for(var i=0; i<months; i++) {

    workCalculate*=(1+percent/100);

    plan.push(Math.floor(workCalculate));

  }

  

  return plan;

}


console.log(getPlan(1000, 6, 30));

console.log(getPlan(500, 3, 50));

.as-console-wrapper { max-height: 100% !important; top: 0; }


查看完整回答
反對(duì) 回復(fù) 2023-03-10
  • 3 回答
  • 0 關(guān)注
  • 162 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)