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
75 changes: 65 additions & 10 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 = 'Alex Whitt';



Expand All @@ -16,7 +19,8 @@ Create a variable called `monthlyInterestRate` and give it the value of interest
Create another variable called `periods` and give it the value of years*12.
*/


let MonthlyInterestRate = interestRate / 12;
let periods = years*12;


// 🏡 Task 2: Harder Math
Expand All @@ -28,18 +32,41 @@ 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
*/


numerator = MonthlyInterestRate * Math.pow(1 + MonthlyInterestRate, periods);
denominator = Math.pow(1 + MonthlyInterestRate, periods) - 1;
MonthlyRate = principal * (numerator / denominator)
console.log(MonthlyRate);


// 🏡 Task 3: Function
/* Create a function called `mortgageCalculator` that combines all of the steps from task 1 and 2 and returns a sentence "{Name}, your monthly rate is ${monthlyRate}"

If your name is `Oscar` mortgageCalculator() should return "Oscar, your monthly rate is 1073.64"
*/
function MortCal(p, i, y, n,s) {

let principal = p;
let interestRate = i;
let years = y;
let name = n;
let credit = s;

let MonthlyInterestRate = interestRate / 12;
let periods = years * 12;

if (credit > 740){
MonthlyInterestRate = MonthlyInterestRate - (MonthlyInterestRate * 0.5) }
else if (credit < 660){
MonthlyInterestRate = MonthlyInterestRate + (MonthlyInterestRate * 0.5)
}

numerator = MonthlyInterestRate * Math.pow(1 + MonthlyInterestRate, periods);
denominator = Math.pow(1 + MonthlyInterestRate, periods) - 1;
MonthlyRate = principal * (numerator / denominator);
return name + ', your monthly rate is $' + MonthlyRate;
}

console.log(MortCal(200000, 0.05, 30, 'Alex Whitt', 700));


// 🏡 Task 4: Arguments and Parameters
Expand All @@ -48,10 +75,7 @@ If your name is `Oscar` mortgageCalculator() should return "Oscar, your monthly
For example,
mortgageCalculator(2000000, 0.05, 30); <-- should return 1,073.64
*/






// 🏡 Task 5: Conditionals
/* Add another paramter to your function called credit score. This parameter will be a number between 0 and 800 (a credit score).
Expand All @@ -60,8 +84,6 @@ Then, add control flow within your function such that IF creditScore is above 74
*/




// 🏡 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 @@ -78,7 +100,39 @@ 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(p,i,y,n,s){
let vari = .02;
for (let l = 0; l < 11; l++){
let principal = p;
let interestRate = i;
let years = y;
let name = n;
let credit = s;



interestRate = interestRate - vari;


let MonthlyInterestRate = interestRate / 12;
let periods = years * 12;

if (credit > 740){
MonthlyInterestRate = MonthlyInterestRate - (MonthlyInterestRate * 0.5) }
else if (credit < 660){
MonthlyInterestRate = MonthlyInterestRate + (MonthlyInterestRate * 0.5)
}
numerator = MonthlyInterestRate * Math.pow(1 + MonthlyInterestRate, periods);
denominator = Math.pow(1 + MonthlyInterestRate, periods) - 1;
MonthlyRate = Math.round(principal * (numerator / denominator));

console.log( `${name}, with an interest rate of ${interestRate.toFixed(3)}, your monthly is $ ${MonthlyRate}`);

vari = vari - .005;
}
}

variableInterestRate(200000,.04,30,"Alex");


// 🌟🌟🌟 STRETCH 🌟🌟🌟//
Expand All @@ -95,3 +149,4 @@ For example, variableInterestRate(200000, 0.04, 30) should console.log:


/* 🏡 Refactor your `variableInterestRate()` function to accept an array of interest rates (make sure to copy and paste as to not lose your work!) */