Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 85 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
/* Create variables for principal, interest rate, and years. Assign them the values 200000, 0.05, and 30 respectively. Create another value called name and give it the value of your own name.
*/


let principal = 200000;
let interestRate = 0.05;
let years = 30;
let name = 'Kayode';



Expand All @@ -15,7 +18,11 @@
(2) Create another variable called `periods` and give it the value of years*12.
*/

let monthlyInterestRate = interestRate/12;
// console.log(monthlyInterestRate);

let periods = years * 12;
// console.log(periods);


// 🏡 Task 2: Harder Math
Expand All @@ -36,6 +43,15 @@ Hint #2: you'll need to use the `math` object for parts of this calculation!
When your math is correct, monthlyRate will equal 1073.64
*/

let numerator = monthlyInterestRate/*(0.04167) */ * (Math.pow((1 + monthlyInterestRate), periods));
// console.log(numerator);//0.018615601308358983

let denominator = ((Math.pow((1 + monthlyInterestRate /*(0.04167) */), periods /*raised to the power of 30*/)) -1);
// console.log(denominator);//3.467744314006156

let monthlyRate = (principal /*(200000) */ * (numerator /*(0.018615601308358983) */ / denominator /*(3.467744314006156) */ )).toFixed(2);

// console.log(monthlyRate);



Expand All @@ -45,7 +61,13 @@ When your math is correct, monthlyRate will equal 1073.64
If your name is `Oscar` mortgageCalculator() should return "Oscar, your monthly rate is 1073.64"
*/

function mortgageCalculator(name){
return `${name} your monthly rate is` + " " + monthlyRate;
}


// console.log(mortgageCalculator("Kayode"));
// console.log(mortgageCalculator("Jackie"));



Expand All @@ -56,7 +78,14 @@ For example,
mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64
*/

function displayMortgage(P, I, N){
let principal = P;
let interestRate = I;
let years = N;
return (P * (numerator / denominator)).toFixed(2);
}

// console.log(displayMortgage(200000, 0.05, 30));



Expand All @@ -68,8 +97,44 @@ Then, add control flow within your function such that IF creditScore is above 74
Hint: To drop an interest rate by 5% you can take monthlyRate and multiply it by 0.95. Similarly, to increase an interest rate by 5% you'd do monthlyRate * 1.05.
*/



// function creditCalculator(P, I, N, credit){
// let principal = P;
// let interestRate = I;
// let years = N;
// if(credit > 740){
// let myMoney = I * 0.95;
// let newRate = I - myMoney;
// return newRate;
// } else if (credit < 660){
// let givenMoney = I * 1.05;
// let newRate = I + givenMoney;
// return newRate;
// } else if (credit => 660 && credit <= 740){
// return I;
// }
// }

// console.log(creditCalculator(200000, 0.05, 30, 700));


function creditCalculator(P, I, N, credit){
let principal = P;
let interestRate = I;
let years = N;
if(credit > 740){
let myMoney = I * 0.05;
let newRate = I - myMoney;
return newRate;
} else if (credit < 660){
let givenMoney = I * 0.05;
let newRate = I + givenMoney;
return newRate;
} else if (credit => 660 && credit <= 740){
return I;
}
}

// console.log(creditCalculator(200000, 0.05, 30, 741));

// 🏡 Task 6: Loops
/* Write a new function called variableInterestRate. This function should be the same as mortgageCalculator, except it should console.log the monthly payment for 10 different interest rates at 0.5% increments plus or minus 2% from the inputted interest rate. Complete these calculations using a for loop.
Expand All @@ -87,6 +152,23 @@ For example, variableInterestRate(200000, 0.04, 30) should console.log:
"{Name}, with an interest rate of 0.06, your monthly rate is $1199"
*/

function variableInterestRate(name, P, I, N){
for(let i = 1; i <= 10; i++){
let principal = P;
let interestRate = (I + i * .005) -.02;
let periods = N * 12;
let monthlyInterestRate = interestRate / 12;
let numerator = monthlyInterestRate * (Math.pow((1 + monthlyInterestRate), periods));
let denominator = ((Math.pow((1 + monthlyInterestRate), periods)) -1);
let monthlyRate = (principal * (numerator / denominator));
console.log(`${name}` + ", with an interest rate of," + interestRate.toFixed(2) + ", your monthly rate is " + monthlyRate.toFixed(2));
}
}
console.log(variableInterestRate("Kayode", 200000, 0.04, 30));
console.log(variableInterestRate("Chris", 300000, 0.07, 20));
console.log(variableInterestRate("Rebecca", 130000, 0.09, 10));





Expand Down