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
74 changes: 69 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// 🌟🌟🌟 M V P 🌟🌟🌟//

// 🏡 Task 1: Variables
/* 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.
/* Create variables for principal, interest rate, and years. Assign them the values 200 000, 0.05, and 30 respectively. Create another value called name and give it the value of your own name.
*/
let principal = 200000;
let intRate = 0.05;
let years = 30;


let name = 'Niko';



Expand All @@ -15,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.
*/

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



Expand All @@ -28,7 +32,12 @@ 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
*/
// P [ I ( 1 + I )^N ] /
// [ ( 1 + I )^N – 1 ]

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



Expand All @@ -37,7 +46,21 @@ 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() {
let principal = 200000;
let intRate = 0.05;
let years = 30;
let name = 'Oscar';

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

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

return `${name}, your monthly rate is ${monthlyRate}`
}



Expand All @@ -48,6 +71,17 @@ If your name is `Oscar` mortgageCalculator() should return "Oscar, your monthly
For example,
mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64
*/
function mortgageCalculator(P, I, N) {

let monthlyInterestRate = I / 12;
let periods = N * 12;

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

return monthlyRate;
}



Expand All @@ -58,6 +92,24 @@ 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 mortgageCalculator(P, I, N, creditScore) {

let monthlyInterestRate = I / 12;
let periods = N * 12;

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

if (creditScore > 740) {
return monthlyRate - 0.5;
} else if (creditScore < 660) {
return monthlyRate + 0.5;
} else {
return monthlyRate;
}
}




Expand All @@ -77,8 +129,20 @@ For example, variableInterestRate(200000, 0.04, 30) should console.log:
"{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 (P, I, N) {

for (i = 0; i < 10; i++){
let monthlyInterestRate = I / 12;
let periods = N * 12;
let name = 'Niko';

let numerator = P * (monthlyInterestRate * Math.pow( 1 + monthlyInterestRate, periods));
let denominator = (Math.pow( 1 + monthlyInterestRate, periods ) - 1);
let monthlyRate = numerator / denominator;
console.log(`${name}, with an interest rate of ${(I - 0.02).toFixed(3)}, your monthly rate is $${Math.round(monthlyRate)}`);
I += 0.005;
}
}


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