在JavaScript中使用对象文本进行循环
提醒:无耻的家庭作业帮助 我正在尝试创建一个偿还信用卡的摊销计划。我被卡住了,因为我想我需要创建一个循环来进行所有的计算,直到信用卡余额为零。我知道基本循环,我知道基本对象;而且,为支付id引用不同的函数(也称为非本地函数)。结合这些原则让我感到困惑 完整的问题细节在代码中注释掉 我试着用不同的循环思想来捣乱;我想在我请求环路帮助之后。我无法让循环正常工作,它通常会无限大并导致浏览器崩溃。但关于上述标准,我有点困惑在JavaScript中使用对象文本进行循环,javascript,arrays,Javascript,Arrays,提醒:无耻的家庭作业帮助 我正在尝试创建一个偿还信用卡的摊销计划。我被卡住了,因为我想我需要创建一个循环来进行所有的计算,直到信用卡余额为零。我知道基本循环,我知道基本对象;而且,为支付id引用不同的函数(也称为非本地函数)。结合这些原则让我感到困惑 完整的问题细节在代码中注释掉 我试着用不同的循环思想来捣乱;我想在我请求环路帮助之后。我无法让循环正常工作,它通常会无限大并导致浏览器崩溃。但关于上述标准,我有点困惑 function displayWelcome() { printLine(
function displayWelcome() {
printLine();
console.log('Welcome to the credit card payoff tool.');
printLine();
console.log('This program will determine the time it \nwill take to pay off a credit card!');
printLine();
}
displayWelcome();
function calculateMinimumPayment(balance, interestRate) {
var calcMinPay = balance * interestRate;
return calcMinPay
}
function generatePaymentId() { // lines 14 - 22 are a closure function.
var count = 0;
function paymentId() {
count ++;
return count;
}
return paymentId;
};
var id = generatePaymentId();
function processPaymentSchedule(balance, interest, minimumPayment) {
var year = 1;
var counter = 0;
while (balance > counter) {
var interestDecimal = interest / 100;
var interestMonthly = interestDecimal / 12;
var interestPaid = balance * interestMonthly;
var payment = {
year: year,
balance: balance,
paymentId: id(),
interest_paid: interestPaid
}
displayPayment(payment);
balance = balance - interestPaid;
return balance;
}
}
function displayPayment(payment) {
console.log(payment.year);
}
printLine();
function printLine() {
console.log('---------------------------------------');
}
printLine();
processPaymentSchedule(1500,18, calculateMinimumPayment());
/*
It should take the balance monthly interest rate and minimum payment as arguments. Each time you calculate a new payment line, create an object literal with properties for the year balance and payment id and interest paid. Pass this object literal to the displayPayment function.
*/
给定这些数字(余额=1500,利息=18%,最低付款额(一个单独的函数,显示余额的2%作为最低付款额))
年度/余额/付款ID/利息ID11492.50 122.50
1484.89 2 67.16
(继续,直到余额为零)
请阅读。帮助我们,帮助你!
最低付款
在付款计算中似乎没有任何作用。除此之外,当您调用calculateMinimumPayment()
时,您的代码不会传入两个必需的参数。哈哈,就像警报一样。很好的尝试。有了这个问题,您是否需要使用一些空白函数?为了让其他人更容易阅读,请尝试将所有函数组合在一起(全部在底部或顶部)。根据说明,“generatePaymentId”函数不需要参数“printLine”函数是一个个人添加。看起来我把循环设置错了,我的计算也错了@spangle-谢谢你的分组提示。只需要。我刚才提到的空函数,关于生成付款id函数。