Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
31 changes: 27 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
/* 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



Expand All @@ -16,8 +19,11 @@ 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.
*/



// Step1: Mortgage Calc
// need # of years converted to months
// and monthly interest
const monthlyInterestRate = interestRate / 12;
const periods = years * 12

// 🏡 Task 2: Harder Math
/* Create your calculator! Use the formula in the ReadMe to run calculations on your numbers. Save the final value into a variable called monthlyRate.
Expand All @@ -28,8 +34,14 @@ 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
*/
// Mortgage Calculator Formula: M = P [ I ( 1 + I )^N ] / [ ( 1 + I )^N – 1 ]


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



// 🏡 Task 3: Function
Expand All @@ -38,9 +50,15 @@ 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(name){
const numerator = monthlyInterestRate * Math.pow(1 + monthlyInterestRate, periods);
const denominator = Math.pow(1 + monthlyInterestRate, periods) - 1;
let monthlyRate = principal * numerator / denominator;
// console.log(name + 'your monthly rate is $' + monthlyRate);
return `${name}, your monthly rate is $ ${monthlyRate}`
}



console.log(mortgageCalculator('Oscar'));

// 🏡 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 @@ -53,6 +71,8 @@ mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64





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

Expand All @@ -78,6 +98,9 @@ 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(){

}



Expand Down