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
}
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</head>
<body>
<p>Open up the console to check your work!</p>
<p> Hello! </p>

<script src="index.js"></script>
</body>
Expand Down
78 changes: 56 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

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




*/
// let principal = 200000;
// let interestRate = 0.05;
// let years = 30;
let name = "Yvette";

// 🏡 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 @@ -15,9 +15,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 = 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 @@ -27,20 +26,25 @@ Hint: while these calculations can be done in one line, it might be helpful to c
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
*/

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

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

// console.log(monthlyRate);

// 🏡 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 mortgageCalculator(monthlyRate){
// return `${name}, your monthly rate is ${monthlyRate}`;
// }




// console.log(mortgageCalculator(monthlyRate));

// 🏡 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 @@ -49,18 +53,41 @@ For example,
mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64
*/

function mortgageCalculator(principal, interestRate, years) {
const monthlyInterestRate = interestRate / 12;
const periods = years * 12;
const numerator = monthlyInterestRate* Math.pow((1 + monthlyInterestRate), periods)
const denominator = Math.pow((1 + monthlyInterestRate), periods) - 1
const monthlyRate = principal * (numerator / denominator)

return `${name}, your monthly rate is ${monthlyRate.toFixed(2)}`;
}


console.log(mortgageCalculator(200000,0.05,40));

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

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, interestRate, years, creditScore) {
// let monthlyInterestRate = interestRate/12;
// const periods = years*12;
// const numerator = monthlyInterestRate* Math.pow((1 + monthlyInterestRate), periods)
// const denominator = Math.pow((1 + monthlyInterestRate), periods) - 1
// const monthlyRate = principal * (numerator / denominator)

// if (creditScore > 740) {
// monthlyInterestRate *= 0.95
// } else if (CreditScore < 660) {
// monthlyInterestRate *= 1.05
// }

// return `${name}, your monthly rate is ${monthlyRate.toFixed(2)}`;
// }
// console.log(mortgageCalculator(200000, 0.05, 30, 750));

// 🏡 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.
Expand All @@ -77,21 +104,28 @@ 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(principal, interestRate, years) {
// for(let i = 0; i < 9 ; i ++)
// {
// const monthlyInterestRate = (interestRate - 0.02 + (i*0.05))/12 ;
// const periods = years*12;
// const numerator = [ monthlyInterestRate* (Math.pow(1 + monthlyInterestRate, periods))];
// const denominator = [Math.pow(1 + monthlyInterestRate, periods) - 1];
// const monthlyRate = principal * (numerator / denominator);
// console.log(`${name}, your monthly rate is ${Math.round(monthlyRate)}`)
// }
// }
// }
// variableInterestRate(200000,0.04, 30)

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


/* 🏡 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!) */
// /* 🏡 Refactor your `variableInterestRate()` function to accept an array of interest rates (make sure to copy and paste as to not lose your work!) */