This is for JavaScript code only. The assassin is closing on you in a deadly gam
ID: 3745336 • Letter: T
Question
This is for JavaScript code only.
The assassin is closing on you in a deadly game of cat and mouse. To defeat him, complete parts I, 2 &3 below: Design and implement a program that will allow us to determine the length of time needed to pay off a credit card balance, as well as the total interest paid The program must implement the following functions: 1. displaywelcome This function should display the welcome message to the user explaining what the program does. 2. calculateMinimumPayment This function calculates the minimum payment. It should take balance and interest rate as arguments and return the minimum payment So the value you display for minimum payment is the value you get from this method. Do not use a literal hardcoded value when you display the minimum payment! 3. generateID: This should be a closure function that generates a new id for the customer. The function should remember the previous id and the new generated id should be the old one plus 1. Make the initial id 1 The object Technique will allow you to obtain the Golden Bow, demonstrate your mastery of the technique by completing Part 4 & 5 below 4. processPaymentschedule This function displays the actual payment schedule. It should take the balance, monthly interest rate and minimum payment as arguments use the 1500, 18% and 2% literal values below. Each time you calculate a new payment line, create an object literal with properties for the Year, Balance, Payment Num, and InterestPaid. Pass this object literal to the displayPayment function See the sample execution below: This 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 Balance on your credit card: 15ee Interest Rate: 18 Assuming a minimum payment of 2% of the balance ($30 min) Your minimum payment would be $ 30.8e PAYOFF SCHEDULE Year Balance Payment Num Interest Paid 1,492.5e 22.5e 1,484.89 1,477.16 1,469.32 44.89 67.16 89.32 517.51 , 207.51 495.28 472.78 449.79 73 74 75 76 1,215.28 1,222.76 1,229.79 227.51 280.92 80.92 173.94 146.55 118.74 90.53 90 61.88 32.81 3.30 30 8.80 5. displayPayment This function should take the payment object literal and display it on the console. See the output example in part 4 85 86 1,277.51 1,2 1,283.94 1,286.55 89 1,288.74 1,29e.53 91 92 93 1,291.88 1,292.81 1,293 94 1,293.35Explanation / Answer
var id=0;
displayWelcome();
takeInput();
function displayWelcome(){
console.log("This 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 payment made.");
}
function calculateMinimumPayment(balance, interestRate){
var balance = balance*(2/100);
if(balance<30){
return 30;
}else{
return balance;
}
}
function generateId(){
id++;
return id;
}
function processPaymentSchedule(balance,monthlyInterestRate,minimumPayment){
var year = 0;
var numPayment = 0;
var interestPaid = 0;
console.log("PAYOFF SCHEDULE");
console.log("---------------------------------------");
console.log("Year" + " " + "Balance" + " " + "PaymentNum" + " " + "InterestPaid");
while(balance>0){
if(numPayment%12==0){
year++;
}
numPayment++;
var interest = balance*(monthlyInterestRate/100);
interestPaid += interest;
balance += interest;
balance -= minimumPayment;
if(balance<0){
balance = 0;
}
var payment = {
Year : year,
Balance: balance,
PaymentNum: numPayment,
InterestPaid: interestPaid
}
displayPayment(payment);
}
}
function displayPayment(payment){
console.log(payment['Year'] + " " + Number(payment['Balance']).toFixed(2) + " " + payment['PaymentNum'] + " " + Number(payment['InterestPaid']).toFixed(2));
}
function takeInput(){
console.log("Balance on your credit card: ");
var balance = readline();
console.log("Interest Rate: ");
var interestRate = readline();
console.log("Assuming a minimun payment of 2% of the balance ($30 min) ");
var minimumPayment = calculateMinimumPayment(balance,interestRate);
console.log("Your minimun payment would be $ "+minimumPayment);
processPaymentSchedule(balance,interestRate/12,minimumPayment);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.