MUST BE IN JAVASCRIPT. NOT JAVA!!!!!!! Design and implement a program that will
ID: 3828668 • Letter: M
Question
MUST BE IN JAVASCRIPT. NOT JAVA!!!!!!!
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:
displayWelcome
This function should display the welcome message to the user explaining what the program does.
calculateMinimumPayment
This function calculates the minimum payment. It should take balance and minimum payment 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!
displayPayments
This function displays the actual payment schedule. It should take the balance and monthly interest rate as arguments.
Use the 1500, 18% and 2% literal values below.
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: 1500
Interest Rate: 18
Assuming a minimum payment of 2% of the balance ($20 min)
Your minimum payment would be $ 30.00
PAYOFF SCHEDULE
_________________
Cont.
This MUST be in Javascript, not java.
Help:
//Main while loop where the balance is greater than 0
//Calculate minim payment using the calculateMinimumPayment function
//Calculate interest paid (monthyInterest = balance * yearlyInterest/12)
//Add monthyInterest to total interest
//Calculate if you need increase year( paymentNumber % 12 == 0)
//displayPayments with all the parts(balance,year,paymentNumber,totalInterest,minimumPayment)
//Increment the payment number
Year Balance Payment Number Interest Paid Minimum Payment 1 $ 1,492.50 1 $ 22.50 $ 30.00 $ 1,485.04 2 $ 44.89 $ 29.85 $ 1,477.61 3 $ 67.16 $ 29.70 $ 1,470.22 4 $ 89.33 $ 29.55 $ 1,462.87 5 $ 111.38 $ 29.40 $ 1,455.56 6 $ 133.32 $ 29.26 $ 1,448.28 7 $ 155.16 $ 29.11 $ 1,441.04 8 $ 176.88 $ 28.97 $ 1,433.83 9 $ 198.50 $ 28.82 $ 1,426.67 10 $ 220.00 $ 28.68 $ 1,419.53 11 $ 241.40 $ 28.53 $ 1,412.43 12 $ 262.70 $ 28.39 2 $ 1,405.37 13 $ 283.88 $ 28.25 $ 1,398.35 14 $ 304.96 $ 28.11 $ 1,391.35 15 $ 325.94 $ 27.97 $ 1,384.40 16 $ 346.81 $ 27.83 $ 1,377.47 17 $ 367.58 $ 27.69 $ 1,370.59 18 $ 388.24 $ 27.55 $ 1,363.73 19 $ 408.80 $ 27.41 $ 1,356.92 20 $ 429.25 $ 27.27 $ 1,350.13 21 $ 449.61 $ 27.14 $ 1,343.38 22 $ 469.86 $ 27.00 $ 1,336.66 23 $ 490.01 $ 26.87 $ 1,329.98 24 $ 510.06 $ 26.73Explanation / Answer
Hi there here is the script. Most of the code is self explanatory. Sorry, I couldn't figure out how much to deduce from balance every month(pay), so I hard coded it. Please confirm with your lecturer how much to deduce(I am not used to credit cards, sorry!). Except that all is set and working.
/**
* Displays a welcome message in the view tag.
*/
var displayWelcome = function () {
// Get the view tag.
let view = document.querySelector("view");
let h3 = document.createElement("h3");
let text = document.createTextNode(
"Welcome to the Credit Calculator App");
h3.appendChild(text);
view.appendChild(h3);
};
/**
* This function calculates the minimum payment
* @param {Float} b - Balance
* @param {Float} pr - Payment Rate in percentage
*/
var calculateMinimumPayment = function (b, pr) {
let min = b * pr / 100;
return (min > 20) ? min : 20;
};
/**
* Prints a nice formatted text.
* @param {Number} balance - Account balance
* @param {Number} year
* @param {Number} paymentNumber
* @param {Number} totalInterest
* @param {Number} minimumPayment
*/
var printFormatted = function (
balance, year, paymentNumber,
totalInterest, minimumPayment ) {
let str = `${year} ${balance.toFixed(2)} ${paymentNumber} ${totalInterest.toFixed(2)} ${minimumPayment.toFixed(2)}`;
console.log(str);
};
/**
* Displays all the payments
* @param {Number} balance
* @param {Number} interest - Yearly Interest.
*/
var displayPayments = function(balance, interest) {
let paidInt = 0;
let paymentNum = 1;
let year = 1;
while (balance > 1) {
let minPay = calculateMinimumPayment(balance, 2);
paidInt += balance * interest/12;
if (paymentNum % 12 === 0)
++year;
printFormatted(balance, year, paymentNum,
paidInt, minPay);
// Sorry I hard coded the deduction, I was not clear how much should
// be deducted. Please change this to whatever necessary.
balance -= 0.05 * balance;
++paymentNum;
}
};
displayPayments(1500, 0.18, 0.2);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.