Javascript问题与开发信用卡时间表的代码
我正在制定信用卡贷款的摊销计划。在运行我编写的代码时,我总是遇到这样或那样的错误。这是“意外标识符”,我似乎找不到它的位置 请帮助我更好地整理代码,以便它能够运行计划Javascript问题与开发信用卡时间表的代码,javascript,object-literal,Javascript,Object Literal,我正在制定信用卡贷款的摊销计划。在运行我编写的代码时,我总是遇到这样或那样的错误。这是“意外标识符”,我似乎找不到它的位置 请帮助我更好地整理代码,以便它能够运行计划 function displayWelcome() { var balance = 1500; var interest = 0.18; var minimumpaymentRate = 0.02; console.log("Welcome! \nThis program will determine the time t
function displayWelcome() {
var balance = 1500;
var interest = 0.18;
var minimumpaymentRate = 0.02;
console.log("Welcome! \nThis program will determine the time to pay off
a
credit card and the interest paid based on the current balance, the
interest rate, and the monthly payments made.")
console.log("Balance on your credit card: $" + balance.toFixed(2))
console.log("Interest Rate: " + (interest * 100) + "%")
console.log("Assuming a minimum payment of 2% of the balance ($20 min)")
console.log("Your minimum payment would be: $" + minimumPaymentment)
console.log("\nYear Balance Payment # Interest Paid
Minimum Payment")
}
function calculateminimumPaymentment(balance, minimumPaymentRate) {
return Math.max(20, balance * minimumPaymentRate);
}
function generatePaymentId() {
var count = 0;
function paymentId() {
count ++;
return count;
}
return paymentId;
};
function processPaymentSchedule(balance, interest, minimumPayment) {
var id = generatePaymentId();
var year = 1;
var payments = 1;
var interestPaid = 0;
var yearChange;
while (balance > 0) {
yearChange = false;
if (payments % 12 == 0) {
year++
yearChange = true;
}
interestPaid += balance * interest / 12;
balance = Math.max(0, balance - (minimumPayment - balance * interest /
12));
minimumPayment = Math.max(20, balance * minimumPaymentRate);
payments++;
}
}
function displayPayment(pmt){
var pmt = {
balance: 1500,
minimumPaymentRate: 0.02,
interest: 0.18
console.log((yearChange ? year:" ") + " " + pmt.balance + "
"
+ payments + " " + pmt.interest + " " +
pmt.minimumPaymentRate);
return displayPayment
};
}
displayWelcome()
processPaymentSchedule(balance, interest, minimumPayment);
预期结果应为:
显示:年度、余额、利息的摊销计划
更新:
我已经更新了下面列出的建议,但现在出现了以下错误:
您的代码确实有问题。有几个错误:
- 应使用``而不是引号创建多行字符串
- 函数displayPayment:移动console.log并返回对象外部
- 在函数外声明余额、利息、最低付款额,以便您可以使用这些变量
“
和”
字符串文本在默认情况下不是多行的。