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
77 changes: 71 additions & 6 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 principal =200000;
const interestRate =0.05;
const years =30;
const name ='Michelle';


// 🏡 Task 1.5: Simple Math
Expand All @@ -16,7 +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 monthlyInterestRate =interestRate/12;
const periods =years*12;


// 🏡 Task 2: Harder Math
Expand All @@ -29,6 +32,15 @@ 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
*/

//M = P [ (I/12)*( 1 + (I/12) )^N ] / [ ( 1 + (I/12) )^N – 1 ]


const numerator = monthlyInterestRate*Math.pow((1+monthlyInterestRate),periods);
const denominator = Math.pow((1+monthlyInterestRate),periods) - 1;

const monthlyRate = principal*(numerator/denominator);

console.log(monthlyRate);



Expand All @@ -38,8 +50,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 mortgageCalculator2(name, monthlyRate){
return name + ' your monthly rate is ' + monthlyRate ;
}


console.log(mortgageCalculator2(name, monthlyRate));


// 🏡 Task 4: Arguments and Parameters
Expand All @@ -50,20 +65,57 @@ mortgageCalculator(2000000, 0.05, 30); <-- should return 1,073.64
*/


function mortgageCalculator(P, I, N) {
const numerator = I*Math.pow((1+I),N);
const denominator = Math.pow((1+I),N) - 1;

const monthlyRate = P*(numerator/denominator);
return monthlyRate;
}

console.log(mortgageCalculator(principal, interestRate, periods));


// 🏡 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).

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

const score = 800;
const score2 = 400;

function mortgageCalculator3(P, I, N, score) {

if(score>740){
I=I-0.5;
} else if (score<660){
I=I+0.5;
}

const numerator = I*Math.pow((1+I),N);
const denominator = Math.pow((1+I),N) - 1;

const monthlyRate = P*(numerator/denominator);
return monthlyRate;
}

console.log(mortgageCalculator3(principal, interestRate, periods, score));


console.log(mortgageCalculator3(principal, interestRate, periods, score2));






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

For example, variableInterestRate(200000, 0.04, 30) should console.log:

Expand All @@ -78,7 +130,20 @@ 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=0; i<=10; i++){
I=I+0.05;

const numerator = I*Math.pow((1+I),N);
const denominator = Math.pow((1+I),N) - 1;

const monthlyRate = P*(numerator/denominator);
console.log(`${name}, with an interest rate of ${I}, your monthly rate is ${monthlyRate}`)
}
}

variableInterestRate(principal, interestRate, periods)


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