Skip to content
Merged
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
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
// 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": "${file}"
}
]
}
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"editor.wordWrap": "on",
"editor.fontSize": 14,
"editor.fontWeight": "500"
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ The completion of these questions is mandatory for MVP. However, passing the qui

After you have completed the requirements, try any of the following challenges. As always, note that these may require additional research beyond what you learned in this module.

- [ ] Add `Property Tax`, `Homeowner's insurance` and `HOA fees` as parameters in your function to calculate total monthly spending on housing
- [x] Add `Property Tax`, `Homeowner's insurance` and `HOA fees` as parameters in your function to calculate total monthly spending on housing
- [ ] Build a calculator function that accepts `monthly payment` and `interest rate` and returns the maximum loan that a person could afford
- [ ] Explore using `window.prompt()` to allow a user to input parameters in the browser
- [ ] Refactor your `variableInterestRate()` function to accept an array of interest rates (make sure to copy and paste as to not lose your work!)
Expand All @@ -74,7 +74,7 @@ After you have completed the requirements, try any of the following challenges.

Follow these steps for completing your project.

1. [ ] Submit a pull request to merge `<firstName-lastName>` branch into master. **Please don't merge your own pull request**
1. [x] Submit a pull request to merge `<firstName-lastName>` branch into master. **Please don't merge your own pull request** (https://github.com/kc0buk/JavaScript-Foundations/pull/1)
2. [ ] Add your TL as a reviewer on the pull-request
3. [ ] Your TL will count the project as complete by merging the branch back into master

Expand Down
120 changes: 110 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +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 int = 0.05;

let years = 30;

let name = 'Jeremiah';


// 🏡 Task 1.5: Simple Math
Expand All @@ -15,8 +20,9 @@
(2) Create another variable called `periods` and give it the value of years*12.
*/

let monthlyInterestRate = int/12;


let periods = years*12;

// 🏡 Task 2: Harder Math
/* Create your calculator! Use the formula in the ReadMe (also below) to run calculations on your numbers. Save the final value into a variable called monthlyRate.
Expand All @@ -30,13 +36,22 @@ Hint: while these calculations can be done in one line, it might be helpful to c
(3) Create a variable called numerator and set it equal to n1 * n2
(4) Create a variable called denominator and set it equal to n1 - 1
(5) Create a variable called monthlyRate and set it equal to numerator/denominator
*/

Hint #2: you'll need to use the `math` object for parts of this calculation!
let n1 = Math.pow((1 + monthlyInterestRate),periods);
// let n2 = n1 * monthlyInterestRate; // remove step 3 above
let numerator = n1 * monthlyInterestRate; // use monthlyInterestRate instead of n2 in step 3 above
let denominator = n1 - 1;
let monthlyRate = principal * (numerator/denominator); // add principal * (numerator/denominator) to step 5 above
console.log(monthlyRate.toFixed(2)); //answers 0.02 -- resolves to 1073.64 with above modifications to instructions.

When your math is correct, monthlyRate will equal 1073.64
*/
// let monthlyRate = (principal * monthlyInterestRate) / (1 - (Math.pow((1 + monthlyInterestRate),periods * -1)));
// console.log(monthlyRate.toFixed(2));

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


// 🏡 Task 3: Function
Expand All @@ -45,9 +60,18 @@ 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 mortgageCalculatorName(P,I,N,Name) {
let principal = P;
let int = I;
let years = N;
let monthlyInterestRate = int/12;
let periods = years*12;
let monthlyRate = (principal * monthlyInterestRate) / (1 - (Math.pow((1 + monthlyInterestRate),periods * -1)));
// let message = Name + ", your monthly rate is " + monthlyRate.toFixed(2);
console.log(Name + ", your monthly rate is " + monthlyRate.toFixed(2));
// return message;
}
mortgageCalculatorName(200000,0.05,30,'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 @@ -56,7 +80,18 @@ For example,
mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64
*/

function mortgageCalculator(P,I,N) {
let principal = P;
let int = I;
let years = N;
let monthlyInterestRate = int/12;
let periods = years*12;
let monthlyRate = (principal * monthlyInterestRate) / (1 - (Math.pow((1 + monthlyInterestRate),periods * -1)));
console.log(monthlyRate);
return monthlyRate;
}

mortgageCalculator(200000,0.05,30);



Expand All @@ -68,7 +103,25 @@ Then, add control flow within your function such that IF creditScore is above 74
Hint: To drop an interest rate by 5% you can take monthlyRate and multiply it by 0.95. Similarly, to increase an interest rate by 5% you'd do monthlyRate * 1.05.
*/


function mortgageCalculator(P,I,N,C) {
let interest;
if (C > 739) {
interest = I - 0.005;
} else if (C < 660) {
interest = I + 0.005;
} else {
interest = I;
}
let principal = P;
let years = N;
let monthlyInterestRate = interest/12;
let periods = years*12;
let monthlyRate = (principal * monthlyInterestRate) / (1 - (Math.pow((1 + monthlyInterestRate),periods * -1)));
// return monthlyRate.toFixed(2);
console.log("Your monthly mortgage payment is " + monthlyRate.toFixed(2));
}

mortgageCalculator(200000,0.05,30,700);


// 🏡 Task 6: Loops
Expand All @@ -87,15 +140,62 @@ 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, C) {
let interest;
if (C > 739) {
interest = I - 0.03;
} else if (C < 660) {
interest = I - 0.02;
} else {
interest = I - 0.025;
}
let count = 0;
for (let i = 0; i < 10; i++) {
interest = interest + .005;
// console.log(interest.toFixed(3));
count = count + 1;
let principal = P;
let years = N;
let monthlyInterestRate = interest/12;
let periods = years*12;
let monthlyRate = (principal * monthlyInterestRate) / (1 - (Math.pow((1 + monthlyInterestRate),periods * -1)));
console.log("{Name}, with an interest rate of " + interest.toFixed(3) + ", your monthly rate is $" + monthlyRate.toFixed(0));
}
}

variableInterestRate(200000,0.04,30,700); // Input -- P: principal, I: interest, N: years, C: credit score

// 🌟🌟🌟 STRETCH 🌟🌟🌟//

/* Attempt any of the stretch goals below once you have finished the work above. Remember as always, these may require additional research beyond what you learned today */

/* 🏡 Add `Property Tax`, `Homeowner's insurance` and `HOA fees` as parameters in your function to calculate total monthly spending on housing */

function mortgageCalculatorComplete(P,I,N,C,T,S,H) {
let principal = P;
let interest;
if (C > 739) {
interest = I - 0.005;
} else if (C < 660) {
interest = I + 0.005;
} else {
interest = I;
}
let years = N;
let monthlyInterestRate = interest/12;
let periods = years*12;
let propTax = T/12;
let insurance = S/12;
let hoaFees = H/12;
let monthlyRate = (principal * monthlyInterestRate) / (1 - (Math.pow((1 + monthlyInterestRate),periods * -1)));
let totalMonthlyCost = monthlyRate + propTax + insurance + hoaFees;
console.log("Your monthly mortgage payment is $" + monthlyRate.toFixed(2));
console.log("Your total monthly housing cost, including property tax, insurance and HOA fees, is $" + totalMonthlyCost.toFixed(2));
// return monthlyRate;
}

mortgageCalculatorComplete(200000,0.05,30,700,1800,1200,2400); /* Input -- P: principal, I: interest, N: years, C: credit score, T: property taxes (annually), S: homeowner's insurance (annually), H: HOA fees (anually) */


/* 🏡 Build a calculator function that accepts `monthly payment` and `interest rate` and returns the maximum loan that a person could afford */

Expand Down