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
80 changes: 75 additions & 5 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.
*/



var principal = 200000;
var interestRate = 0.05;
var years = 30;
let name = "Shaun";


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

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



Expand All @@ -29,7 +33,10 @@ 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 compound = Math.pow((1+ monthlyInterestRate), periods);
let numerator = monthlyInterestRate * compound;
let denominator = compound - 1;
let monthlyRate = principal * (numerator / denominator);


// 🏡 Task 3: Function
Expand All @@ -38,18 +45,41 @@ 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() {

monthlyInterestRate = interestRate / 12;
periods = years * 12;
compound = Math.pow((1+ monthlyInterestRate), periods);
numerator = monthlyInterestRate * compound;
denominator = compound - 1;
monthlyRate = principal * (numerator / denominator);

return `${name}, your monthly rate is ${monthlyRate.toFixed(2)}`;
}

console.log(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.

For example,
mortgageCalculator(2000000, 0.05, 30); <-- should return 1,073.64
mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64
*/

function mortgageCalculator2(principal, interestRate, years) {

monthlyInterestRate = interestRate / 12;
periods = years * 12;
compound = Math.pow((1+ monthlyInterestRate), periods);
numerator = monthlyInterestRate * compound;
denominator = compound - 1;
monthlyRate = principal * (numerator / denominator);
return `${name}, your monthly rate is ${monthlyRate.toFixed(2)}`;
}

console.log(mortgageCalculator2(150000, 0.05, 30));



Expand All @@ -59,6 +89,28 @@ mortgageCalculator(2000000, 0.05, 30); <-- should return 1,073.64
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.
*/

function mortgageCalculator3(principal, interestRate, years, creditScore) {

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

monthlyInterestRate = interestRate / 12;
periods = years * 12;
compound = Math.pow((1+ monthlyInterestRate), periods);
numerator = monthlyInterestRate * compound;
denominator = compound - 1;
monthlyRate = principal * (numerator / denominator);


return name + ", your monthly rate is " + monthlyRate.toFixed(2);
}

console.log(mortgageCalculator3(200000, 0.05, 30, 600));



Expand All @@ -78,14 +130,32 @@ 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(principal, interestRate, years){

let varRate = interestRate;

for(let i = 0; i <= 8; i++){
varRate=interestRate-.02;
interestRate=interestRate+.005;
varRate = +varRate.toFixed(3);

monthlyInterestRate = varRate / 12;
periods = years * 12;
compound = Math.pow((1+ monthlyInterestRate), periods);
numerator = monthlyInterestRate * compound;
denominator = compound - 1;
monthlyRate = principal * (numerator / denominator);

console.log(`${name}, with an interest rate of ${varRate}, your monthly rate is $${Math.round(monthlyRate)}`);
}
}

variableInterestRate(200000, 0.04, 30);
// 🌟🌟🌟 STRETCH 🌟🌟🌟//

/* Attempt any of the stretch goals below once you have finished the work above. Remember as always, these may require additional research beyond what you learned today */

/* 🏡 Add `Property Tax`, `Homeowner's insurance` and `HOA fees` as parameters in your function to calculate total monthly spending on housing */
/* 🏡 Add `}`Property Tax`, `Homeowner's insurance` and `HOA fees` as parameters in your function to calculate total monthly spending on housing */


/* 🏡 Build a calculator function that accepts `monthly payment` and `interest rate` and returns the maximum loan that a person could afford */
Expand Down