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
56 changes: 48 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +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.
*/



const P = 200000;
const interestRate = .05;
const years = 30;
const name = 'Brandon'


// 🏡 Task 1.5: Simple Math
Expand All @@ -16,8 +18,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.
*/



const I = interestRate / 12;
const N = years * 12;

// 🏡 Task 2: Harder Math
/* Create your calculator! Use the formula in the ReadMe to run calculations on your numbers. Save the final value into a variable called monthlyRate.
Expand All @@ -29,16 +31,37 @@ 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 monthlyRate = P * (I * Math.pow(1 + I , N)) / (Math.pow( 1 + I, N) - 1);

// 🏡 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 mortgageCalculator (P,I,N,creditScore) {

let newI = I;

if (creditScore > 740) {
newI = I - .005;
}else if (creditScore < 660) {
newI = I + .005;
}else {
newI = I;
}

let monthlyInterestRate = newI / 12;
let periods = N * 12;
let name = 'Brandon'

let monthlyRate = P * (monthlyInterestRate * Math.pow(1 + monthlyInterestRate , periods)) / (Math.pow( 1 + monthlyInterestRate, periods) - 1);
monthlyRate = Math.round(monthlyRate * 100) / 100;

let solution = name + ', your monthly rate is $' + monthlyRate;

return solution
}



Expand Down Expand Up @@ -78,7 +101,24 @@ 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,N) {



for (let i = I - .02; i < (i + .04); i + .005) {

let newI = i;

let monthlyInterestRate = newI / 12;
let periods = N * 12;
let name = 'Brandon';

let monthlyRate = P * (monthlyInterestRate * Math.pow(1 + monthlyInterestRate , periods)) / (Math.pow( 1 + monthlyInterestRate, periods) - 1);
monthlyRate = Math.round(monthlyRate * 100) / 100;

console.log( name + ', with an interest rate of' + i + ',your monthly rate is $' + monthlyRate);
}
}


// 🌟🌟🌟 STRETCH 🌟🌟🌟//
Expand Down