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
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}\\index.js"
}
]
}
77 changes: 72 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
/* 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.
*/

let principal = 200000;

let interestRate = 0.05;

let years = 30;

let firstName = 'Sharon';

// 🏡 Task 1.5: Simple Math
/* To create a monthly mortgage rate calculator, we need to know the number of years in months and the monthly interest rate.
Expand All @@ -16,8 +20,9 @@ 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;

// 🏡 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,7 +33,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
*/
let numerator = Math.pow (monthlyInterestRate + 1, periods) * monthlyInterestRate;

let denominator = Math.pow(1 + monthlyInterestRate,periods) - 1;

let payment = (principal*(numerator / denominator));

let monthlyPayment = payment.toFixed(2);

console.log (monthlyPayment);



Expand All @@ -37,7 +50,22 @@ 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 interestRate = 0.05;
let years = 30;
let firstName = 'Sharon';
let monthlyInterestRate = interestRate / 12;
let periods = years * 12;
let numerator = Math.pow (monthlyInterestRate + 1, periods) *monthlyInterestRate;
let denominator = Math.pow(1 + monthlyInterestRate,periods) - 1;
let payment = (principal*(numerator / denominator));
let monthlyPayment = payment.toFixed(2);
return (monthlyPayment);
}

console.log ( 'Sharon',"your monthly rate is", monthlyPayment);




Expand All @@ -49,7 +77,18 @@ For example,
mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64
*/


function mortgageCalculator(principal, interestRate, years){
let firstName = 'Sharon';
let monthlyInterestRate = interestRate / 12;
let periods = years * 12;
let numerator = Math.pow (monthlyInterestRate + 1, periods) *monthlyInterestRate;
let denominator = Math.pow(1 + monthlyInterestRate,periods) - 1;
let payment = (principal*(numerator / denominator));
let monthlyPayment = payment.toFixed(2);
return (monthlyPayment);
}

console.log ( 'Sharon',"your monthly rate is", mortgageCalculator(200000, 0.05, 30))



Expand All @@ -58,7 +97,20 @@ 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(principal, interest, years, creditScore){
if (creditScore > 740) { interest -= .005 };

let firstName = 'Sharon';
let monthlyInterestRate = interest / 12;
let periods = years * 12;
let numerator = Math.pow (monthlyInterestRate + 1, periods) *monthlyInterestRate;
let denominator = Math.pow(1 + monthlyInterestRate, periods) - 1;
let payment = (principal*(numerator / denominator));
let monthlyPayment = payment.toFixed(2);
return (monthlyPayment);
}

console.log ( 'Sharon',"your monthly rate is", mortgageCalculator(200000, 0.05, 30, 800))



Expand All @@ -78,8 +130,22 @@ 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, interest, years) {
interest = 0.02;
for (let i = 0; i <= 8; i++) {
let firstName = "Sharon";
let monthlyInterestRate = interest / 12;
let periods = years * 12;
let numerator = Math.pow (monthlyInterestRate + 1, periods) *monthlyInterestRate;
let denominator = Math.pow(1 + monthlyInterestRate, periods) - 1;
let payment = (principal*(numerator / denominator));
let monthlyPayment = Math.round(payment);
interest += 0.005;
console.log( 'Sharon, with an interest rate of '+ interest.toFixed(3),
"your monthly rate is $" + ( monthlyPayment))}
return;
}
variableInterestRate (200000, 0.04, 30 );

// 🌟🌟🌟 STRETCH 🌟🌟🌟//

Expand All @@ -95,3 +161,4 @@ For example, variableInterestRate(200000, 0.04, 30) should console.log:


/* 🏡 Refactor your `variableInterestRate()` function to accept an array of interest rates (make sure to copy and paste as to not lose your work!) */