Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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 .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Compiled
*.elc

# Packaging
.cask

# Backup files
*~

# Undo-tree save-files
*.~undo-tree

# Autosave
\#*\#

# impatient-mode sockets
.\#*

# scratch directory for expirimental work
scratch
9 changes: 9 additions & 0 deletions .indium.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"configurations": [
{
"name": "JavaScript Foundations",
"type": "node",
"program": "node"
}
]
}
214 changes: 157 additions & 57 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,106 +1,206 @@
// 🌟🌟🌟 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 200000, 0.05, and 30 respectively. Create another
* value called name and give it the value of your own name.
*/

const principle = 200000;
const interestRate = 0.05;
const years = 30;
const name = "Harry Henry Gebel";

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

(1) Create a variable called `monthlyInterestRate` and give it the value of interest rate divided by 12.
(2) Create another variable called `periods` and give it the value of years*12.
*/
/* To create a monthly mortgage rate calculator, we need to know the
* number of years in months and the monthly interest rate.

(1) Create a variable called `monthlyInterestRate` and give it the
value of interest rate divided by 12.

(2) Create another variable called `periods` and give it the value of
years*12.
*/

const monthlyInterestRate = interestRate / 12.0;
const 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.
/* 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.

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

Hint: while these calculations can be done in one line, it might be helpful to create seperate variables to hold parts of your equation. That might look like this:
* Hint: while these calculations can be done in one line, it might be
* helpful to create seperate variables to hold parts of your
* equation. That might look like this:

(1) Create a variable called n1 and set it equal to (1 + I )^N
(2) Create a variable called n2 and set it equal to n1 * I
(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
(1) Create a variable called n1 and set it equal to (1 + I )^N

Hint #2: you'll need to use the `math` object for parts of this calculation!
(2) Create a variable called n2 and set it equal to n1 * I

When your math is correct, monthlyRate will equal 1073.64
*/
(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!

// 🏡 Task 3: Function
/* Create a function called `mortgageCalculator` that combines all of the steps from task 1 and 2 and returns a sentence "{Name}, your monthly rate is ${monthlyRate}"

If your name is `Oscar` mortgageCalculator() should return "Oscar, your monthly rate is 1073.64"
*/
* When your math is correct, monthlyRate will equal 1073.64
*/

const compoundedInterest = Math.pow(1 + monthlyInterestRate, periods);
const monthlyRate = principle * (
(monthlyInterestRate * compoundedInterest) /
(compoundedInterest - 1));

// 🏡 Task 3: Function
/* Create a function called `mortgageCalculator` that combines all of
* the steps from task 1 and 2 and returns a sentence "{Name}, your
* monthly rate is ${monthlyRate}"

* If your name is `Oscar` mortgageCalculator() should return "Oscar,
* your monthly rate is 1073.64"
*/

function mortgageCalculatorName() {
console.log (`${name}, your monthly rate is ${monthlyRate.toFixed(2)}`);
}

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

For example,
mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64
*/

/* Substitute the variables in your functions for parameters such that
* you can substitute `P`, `I`, and `N` when you call the function.

* For example,
* mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64
*/

function mortgageCalculator(principle, interestRate, years) {
const monthlyInterestRate = interestRate / 12.0;
const periods = years * 12;
const compoundedInterest = Math.pow(1 + monthlyInterestRate, periods)

return principle * (
(monthlyInterestRate * compoundedInterest) /
(compoundedInterest - 1));
}

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

* 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 mortgageCalculatorCredit(principle,
interestRate,
years,
creditScore) {
const baseMonthlyRate = mortgageCalculator(principle,
interestRate,
years);
let adjustment = 1.0;
if (creditScore > 740) {
adjustment = 1.05;
} else if (creditScore < 660) {
adjustment = 0.95;
}

return baseMonthlyRate * adjustment;
}

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

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

* "{Name}, with an interest rate of 0.02, your monthly rate is $739"
* "{Name}, with an interest rate of 0.025, your monthly rate is $790"
* "{Name}, with an interest rate of 0.03, your monthly rate is $843"
* "{Name}, with an interest rate of 0.035, your monthly rate is $898"
* "{Name}, with an interest rate of 0.04, your monthly rate is $955"
* "{Name}, with an interest rate of 0.045, your monthly rate is $1013"
* "{Name}, with an interest rate of 0.05, your monthly rate is $1074"
* "{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 (principle, interestRate, years) {
for (sampleInterestRate = interestRate - 0.02;
sampleInterestRate <= interestRate + 0.02;
sampleInterestRate += 0.005) {
let sampleRate = mortgageCalculator(principle,
sampleInterestRate,
years);
console.log(`${name}, with an interest rate of ` +
`${sampleInterestRate.toFixed(3)}, your monthly rate is ` +
`${sampleRate.toFixed(2)}`)};
}

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


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

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

"{Name}, with an interest rate of 0.02, your monthly rate is $739"
"{Name}, with an interest rate of 0.025, your monthly rate is $790"
"{Name}, with an interest rate of 0.03, your monthly rate is $843"
"{Name}, with an interest rate of 0.035, your monthly rate is $898"
"{Name}, with an interest rate of 0.04, your monthly rate is $955"
"{Name}, with an interest rate of 0.045, your monthly rate is $1013"
"{Name}, with an interest rate of 0.05, your monthly rate is $1074"
"{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"
*/
/* 🏡 Build a calculator function that accepts `monthly payment` and
* `interest rate` and returns the maximum loan that a person could
* afford */

/* Solve for P

I(1 + I)^N
M = P -------------
(1 + I)^N - 1

M I(1 + I)^N
- = -------------
P (1 + I)^N - 1

// 🌟🌟🌟 STRETCH 🌟🌟🌟//
P (1 + I)^N - 1
- = -------------
M I(1 + I)^N

/* 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 */
M((1 + I)^N - 1)
P = ----------------
I(1 + I)^N

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

function affordabilityCalculator (monthlyPayment, interestRate, years) {
const periods = years * 12;
const monthlyInterestRate = interestRate / 12;
const compoundedInterest = Math.pow(1 + monthlyInterestRate, periods);

/* 🏡 Build a calculator function that accepts `monthly payment` and `interest rate` and returns the maximum loan that a person could afford */
return ((monthlyPayment * (compoundedInterest - 1)) /
(monthlyInterestRate * compoundedInterest));
}


/* 🏡 Explore using `window.prompt()` to allow a user to input parameters in the browser */
/* 🏡 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!) */
/* 🏡 Refactor your `variableInterestRate()` function to accept an
* array of interest rates (make sure to copy and paste as to not lose
* your work!) */