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

var principal = 200000;
var interestRate = 0.05;
var years = 30;



var name = "Felipe Slaughter-Quintero";

// 🏡 Task 1.5: Simple Math
/* To create a monthly mortgage rate calculator, we need to know the number of years in months and the monthly interest rate.
Expand All @@ -15,7 +17,8 @@
(2) Create another variable called `periods` and give it the value of years*12.
*/


var monthlyInterestRate = interestRate / 12;
var periods = years * 12;


// 🏡 Task 2: Harder Math
Expand All @@ -25,7 +28,7 @@ M = P [ I ( 1 + I )^N ] / [ ( 1 + I )^N – 1 ]

Hint: while these calculations can be done in one line, it might be helpful to create seperate variables to hold parts of your equation. That might look like this:

(1) Create a variable called n1 and set it equal to (1 + monthlyInterestRate )^N
(1) Create a variable called n1 and set it equal to (1 + monthlyInterestRate )^n
(2) Create a variable called numerator and set it equal to p * n1 * monthlyInterestRate
(3) Create a variable called denominator and set it equal to n1 - 1
(4) Create a variable called monthlyRate and set it equal to numerator/denominator
Expand All @@ -35,18 +38,33 @@ 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
*/



var n1 = Math.pow((1 + monthlyInterestRate), periods);
var numerator = principal * n1 * monthlyInterestRate;
var denominator = n1 - 1;
var monthlyRate = (numerator/denominator).toFixed(2);

// 🏡 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 (){
var principal = 200000;
var interestRate = 0.05;
var years = 30;
var name = "Felipe Slaughter-Quintero";
var monthlyInterestRate = interestRate / 12;
var periods = years * 12;

var n1 = Math.pow((1 + monthlyInterestRate), periods);
var numerator = principal * n1 * monthlyInterestRate;
var denominator = n1 - 1;
var monthlyRate = (numerator/denominator).toFixed(2);
console.log(`${name}, your monthly rate is ${monthlyRate}`);
}


mortgageCalculator();

// 🏡 Task 4: Arguments and Parameters
/* Substitute the variables in your functions for parameters such that you can substitute `P`, `I`, and `N` when you call the function.
Expand All @@ -56,17 +74,60 @@ mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64
*/


function mortgageCalculator (P,I,N){
var principal = P;
var interestRate = I;
var years = N;
var periods = years * 12;
var monthlyInterestRate = interestRate / 12;

var n1 = Math.pow((1 + monthlyInterestRate), periods);
var numerator = principal * n1 * monthlyInterestRate;
var denominator = n1 - 1;
var monthlyRate = (numerator/denominator).toFixed(2);
console.log(monthlyRate);
};

mortgageCalculator(200000, 0.05, 30);

// 🏡 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).
/* Add another parameter to your function called credit score. This parameter will be a number between 0 and 800 (a credit score).

Then, add control flow within your function such that IF creditScore is above 740, interest rate drops by 0.5%, if credit score is below 660, interest rate increases by 0.5% and if credit score is anywhere between 660 and 740 interest rate doesn't change.

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.
*/

var name = "Felipe Slaughter-Quintero";

function mortgageCalculator (P,I,N,C, name1){
var principal = P;
var interestRate = I;
var years = N;
var creditScore = C;

if (creditScore > 740 ){
interestRate = I * 0.95;
}
else if (creditScore < 660){
interestRate = I * 1.05;
}
else {interestRate = I}

var periods = years * 12;
var monthlyInterestRate = interestRate / 12;

var n1 = Math.pow((1 + monthlyInterestRate), periods);
var numerator = principal * n1 * monthlyInterestRate;
var denominator = n1 - 1;
var monthlyRate = (numerator/denominator).toFixed(2);

console.log(`${name}, your monthly rate is ${monthlyRate}`);
}

mortgageCalculator(200000, 0.05, 30, 640);
mortgageCalculator(200000, 0.05, 30, 700);
mortgageCalculator(200000, 0.05, 30, 790);



Expand All @@ -86,6 +147,31 @@ For example, variableInterestRate(200000, 0.04, 30) should console.log:
"{Name}, with an interest rate of 0.06, your monthly rate is $1199"
*/

var name = "Felipe Slaughter";

function variableInterestRate (P,I,N){

var principal = P;
var interestRate = I +- 0.025;
var years = N;

for (let i = 0; i < 9; i++) {
interestRate += 0.005;

var periods = years * 12;
var monthlyInterestRate = interestRate / 12;

var n1 = Math.pow((1 + monthlyInterestRate), periods);
var numerator = principal * n1 * monthlyInterestRate;
var denominator = n1 - 1;
var monthlyRate = Math.round(numerator/denominator);

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

// called function while testing code for Task 6
variableInterestRate(200000, 0.04, 30)



Expand Down