创建一个基本的JavaScript以添加100,即15次,等于1500。但是,低于我的代码并不会触发,而只会返回0。我敢肯定,我已经在考虑这个问题或让我变量被错误地调用。
var monthlyDeposit = 100; // Code will be tested with values: 100 and 130
var accountBalance = 0;
/* Your solution goes here */
for (c = accountBalance; c <= 15; c += monthlyDeposit) {
console.log(c);
}
答案 0 :(得分:2)
如果从Javascript
开始,请让c
变量处理迭代,并执行逻辑以在循环体内递增accountBalance
。这将使循环执行15
次更加明确。
var monthlyDeposit = 100; // Code will be tested with values: 100 and 130
var accountBalance = 0;
/* Your solution goes here */
for (let c = 0; c < 15; c++)
{
accountBalance += monthlyDeposit;
}
console.log("accountBalance is: " + accountBalance);
答案 1 :(得分:1)
在您的代码中,您将monthlyDeposit
的值添加到c
,因此对于第一次迭代,c
的值将为100,这不满足{{1} }。
c <= 15
答案 2 :(得分:0)
var monthlyDeposit = 100; // Code will be tested with values: 100 and 130
var accountBalance = 0;
/* Your solution goes here */
for (c = accountBalance; c <= 15; c += monthlyDeposit) {
console.log(c); //<- c is 0 after that it will become 100 which is not less than 15
}
由于第一次迭代后c
的值为100
,该值不小于15
,因此您将c
的值设为0
答案 3 :(得分:0)
您要在c上加上100,但要检查的条件是<=15。您的循环只会运行一次。
将条件设为c <= 1500,它应该可以工作。
答案 4 :(得分:0)
最初为c=0
。第一次迭代c = 100
后,它大于15
。如果要运行15次。您设置了条件c <= 1500
var monthlyDeposit = 100; // Code will be tested with values: 100 and 130
var accountBalance = 0;
/* Your solution goes here */
for (c = accountBalance; c <= 1500; c += monthlyDeposit) {
console.log(c);
}
答案 5 :(得分:0)
var monthlyDeposit = 100; // Code will be tested with values: 100 and 130
var accountBalance = 0;
/* Your solution goes here */
for (let c=1; c<= 15; c++) {
accountBalance+=monthlyDeposit;
}
console.log("Account Balance:"+accountBalance);