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
95 changes: 93 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@
/* 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 principal = 200000;
console.log(principal);

const interestRate = .05;
console.log(interestRate);

const years = 30;
console.log(years);

const name = "Stephanie";
console.log(name);



Expand All @@ -16,6 +26,13 @@ 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 monthlyInterestRate = interestRate / 12;
console.log(monthlyInterestRate);


const periods = years * 12;
console.log(periods);




Expand All @@ -29,6 +46,21 @@ 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
*/

const intrestPlusOne = monthlyInterestRate + 1;

const exponentialInterest = Math.pow(intrestPlusOne, periods);

const numerator = monthlyInterestRate * exponentialInterest;

const denominator = exponentialInterest - 1;

const dividend = numerator / denominator;

const monthlyPayment = principal * dividend;

console.log(monthlyPayment.toFixed(2));





Expand All @@ -38,9 +70,11 @@ 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() {
// return name + ", your monthly rate is " + monthlyPayment.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.
Expand All @@ -49,7 +83,20 @@ For example,
mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64
*/

function mortgageCalculator(principal, interestRate, years) {
const monthlyInterestRate = interestRate / 12;
const periods = years * 12;

const intrestPlusOne = monthlyInterestRate + 1;
const exponentialInterest = Math.pow(intrestPlusOne, periods);
const numerator = monthlyInterestRate * exponentialInterest;
const denominator = exponentialInterest - 1;
const dividend = numerator / denominator;
const monthlyPayment = principal * dividend;
return monthlyPayment.toFixed(2);
}

// console.log(mortgageCalculator(200000, .05, 30));



Expand All @@ -59,6 +106,32 @@ mortgageCalculator(200000, 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 monthlyPaymentCalculator(principal, interestRate, years, creditScore) {
let adjustedInterestRate = interestRate

if (creditScore > 740) {
adjustedInterestRate = interestRate - 0.005;
} else if (creditScore < 660) {
adjustedInterestRate = interestRate + 0.005;
}
// else if (creditScore > 660 && creditScore < 740) {
// adjustedInterestRate = interestRate;
// }
// above comments are another way to do it but unneccessary

const monthlyInterestRate = adjustedInterestRate / 12;
const periods = years * 12;

const intrestPlusOne = monthlyInterestRate + 1;
const exponentialInterest = Math.pow(intrestPlusOne, periods);
const numerator = monthlyInterestRate * exponentialInterest;
const denominator = exponentialInterest - 1;
const dividend = numerator / denominator;
const monthlyPayment = principal * dividend;
return monthlyPayment.toFixed(2);
}

console.log(monthlyPaymentCalculator(200000, .05, 30, 755));



Expand All @@ -71,14 +144,32 @@ For example, variableInterestRate(200000, 0.04, 30) should console.log:
"{Name}, with an interest rate of 0.025, your monthly rate is $790"
"{Name}, with an interest rate of 0.03, your monthly rate is $843"
"{Name}, with an interest rate of 0.035, your monthly rate is $898"

"{Name}, with an interest rate of 0.04, your monthly rate is $955"

"{Name}, with an interest rate of 0.045, your monthly rate is $1013"
"{Name}, with an interest rate of 0.05, your monthly rate is $1074"
"{Name}, with an interest rate of 0.055, your monthly rate is $1136"
"{Name}, with an interest rate of 0.06, your monthly rate is $1199"
*/


function variableInterestRate(principal, interestRate, years) {
console.log("Start");
let i = interestRate - .02;
const end = interestRate + .02;

// i++ means i = i + 1
// i += anyNumber means i = i + anyNumber
for (i; i <= end; i += .005) {
console.log(name + ", with an interest rate of " + i.toFixed(3) + ", your monthly rate is $" + Math.round(mortgageCalculator(principal, i, years)));
}
}
variableInterestRate(200000, .04, 30);
variableInterestRate(300000, .06, 30);
// .5% increments
// + && - 2% from interestRate
//print: name + ", with an interest rate of " + the fucking shit + ", your monthly rate is " + monthlyPayment


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