From 1bde6f5930c39795bf9ac1ddf875994ea512247a Mon Sep 17 00:00:00 2001 From: Trevor Locke Date: Fri, 16 Oct 2020 00:06:17 -0500 Subject: [PATCH 1/6] Finished Task 2 --- index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 667af155..eb9a051e 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,10 @@ /* 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 = 'Trevor' @@ -14,6 +18,8 @@ (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. */ +let monthlyInterestRate = (interestRate / 12); +let periods = (years * 12); @@ -35,7 +41,11 @@ 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 n1 = Math.pow ((1+ monthlyInterestRate), periods); + let numerator = (principal * n1 * monthlyInterestRate) + let denominator = (n1 - 1); + let monthlyRate = (numerator / denominator) + console.log(monthlyRate) // 🏡 Task 3: Function From 255cd8ae696dd2582df76e16534c83bc3ac63b9e Mon Sep 17 00:00:00 2001 From: Trevor Locke Date: Fri, 16 Oct 2020 14:08:17 -0500 Subject: [PATCH 2/6] Almost done, Working on Task 6 --- index.js | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 79 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index eb9a051e..4440534c 100644 --- a/index.js +++ b/index.js @@ -45,8 +45,7 @@ let n1 = Math.pow ((1+ monthlyInterestRate), periods); let numerator = (principal * n1 * monthlyInterestRate) let denominator = (n1 - 1); let monthlyRate = (numerator / denominator) - console.log(monthlyRate) - + let result = Math.floor(monthlyRate * 100) / 100 // 🏡 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}" @@ -54,9 +53,22 @@ let n1 = Math.pow ((1+ monthlyInterestRate), periods); 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 name = 'Trevor' +// let monthlyInterestRate = (interestRate / 12); +// let periods = (years * 12);let n1 = Math.pow ((1+ monthlyInterestRate), periods); +// let numerator = (principal * n1 * monthlyInterestRate) +// let denominator = (n1 - 1); +// let monthlyRate = (numerator / denominator) +// let result = Math.floor(monthlyRate * 100) / 100 +// console.log(`Hi ${name} your monthly rate is ${result}`) +// } - +// mortgageCalculator() // 🏡 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. @@ -65,9 +77,22 @@ For example, mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64 */ +// function mortgageCalculator(p, i, n){ +// let principal = p; +// let interestRate = i; +// let years = n; +// let name = 'Trevor' +// let monthlyInterestRate = (interestRate / 12); +// let periods = (years * 12);let n1 = Math.pow ((1+ monthlyInterestRate), periods); +// let numerator = (principal * n1 * monthlyInterestRate) +// let denominator = (n1 - 1); +// let monthlyRate = (numerator / denominator) +// let result = Math.floor(monthlyRate * 100) / 100 +// console.log(`Hi ${name} your monthly rate is ${result}`) +// } - +// mortgageCalculator(200000, 0.05, 30) // 🏡 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). @@ -77,7 +102,31 @@ 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 principal = p; + let interestRate = i; + if(c > 740) { + interestRate *= 0.95; + } if (c < 640) { + interestRate *= 1.05; + } + + let years = n; + let name = 'Trevor' + let monthlyInterestRate = (interestRate / 12); + let periods = (years * 12);let n1 = Math.pow ((1+ monthlyInterestRate), periods); + let numerator = (principal * n1 * monthlyInterestRate) + let denominator = (n1 - 1); + let monthlyRate = (numerator / denominator) + let result = Math.floor(monthlyRate * 100) / 100 + + + + // console.log(`Hi ${name} your monthly rate is ${result}`) +} + +mortgageCalculator(200000, 0.05, 30, 780) // 🏡 Task 6: Loops @@ -96,7 +145,33 @@ 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){ + for (let x = i - 0.02; x < i + 0.02; x += 0.0005) { + let principal = p; + let interestRate = x; + // if(c > 740) { + // interestRate *= 0.95; + // } if (c < 640) { + // interestRate *= 1.05; + // } + + let years = n; + let name = 'Trevor' + let monthlyInterestRate = (interestRate / 12); + let periods = (years * 12); + let n1 = Math.pow ((1+ monthlyInterestRate), periods); + let numerator = (principal * n1 * monthlyInterestRate) + let denominator = (n1 - 1); + let monthlyRate = (numerator / denominator) + let result = (Math.round(monthlyRate * 100) / 100).toFixed(0);} + + + + console.log(`${name}, with an intrest rate of ${interestRate} your monthly rate is ${result}`) + +} +variableInterestRate(200000, 0.04, 30) // 🌟🌟🌟 STRETCH 🌟🌟🌟// From 3084ba2a24927026cd40d266d0e6ef7e1838a9fd Mon Sep 17 00:00:00 2001 From: Trevor Locke Date: Fri, 16 Oct 2020 14:20:12 -0500 Subject: [PATCH 3/6] Updated Task 5 --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 4440534c..c617a7a6 100644 --- a/index.js +++ b/index.js @@ -118,7 +118,7 @@ function mortgageCalculator(p, i, n, c){ let numerator = (principal * n1 * monthlyInterestRate) let denominator = (n1 - 1); let monthlyRate = (numerator / denominator) - let result = Math.floor(monthlyRate * 100) / 100 + let result = (Math.round(monthlyRate * 100) / 100).toFixed(2); From 4082aec9f8b964b4baeead5ccee58ef4742fb964 Mon Sep 17 00:00:00 2001 From: Trevor Locke Date: Fri, 16 Oct 2020 16:13:47 -0500 Subject: [PATCH 4/6] Finished Task 6 Finally --- index.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index c617a7a6..4405df8d 100644 --- a/index.js +++ b/index.js @@ -146,9 +146,11 @@ For example, variableInterestRate(200000, 0.04, 30) should console.log: */ function variableInterestRate(p, i, n){ - for (let x = i - 0.02; x < i + 0.02; x += 0.0005) { + for (let x = i - 0.02; x < i + 0.02; x += 0.005) { let principal = p; - let interestRate = x; + let rate = x.toFixed(3); + let interestRate = rate*1 + // if(c > 740) { // interestRate *= 0.95; // } if (c < 640) { @@ -156,22 +158,20 @@ function variableInterestRate(p, i, n){ // } let years = n; - let name = 'Trevor' - let monthlyInterestRate = (interestRate / 12); let periods = (years * 12); let n1 = Math.pow ((1+ monthlyInterestRate), periods); let numerator = (principal * n1 * monthlyInterestRate) let denominator = (n1 - 1); - let monthlyRate = (numerator / denominator) - let result = (Math.round(monthlyRate * 100) / 100).toFixed(0);} + let monthlyRate = (numerator / denominator); + let result = (Math.round(monthlyRate * 100) / 100).toFixed(0); console.log(`${name}, with an intrest rate of ${interestRate} your monthly rate is ${result}`) - + } } -variableInterestRate(200000, 0.04, 30) +variableInterestRate(200000, 0.04, 30); // 🌟🌟🌟 STRETCH 🌟🌟🌟// From 50061ffa99fb7dc6a2c5b9831873eb2ae2aa69db Mon Sep 17 00:00:00 2001 From: Trevor Locke Date: Fri, 16 Oct 2020 16:51:49 -0500 Subject: [PATCH 5/6] Working on Stretch 1 --- index.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 4405df8d..ab8d20ce 100644 --- a/index.js +++ b/index.js @@ -102,7 +102,7 @@ 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 mortgageCalculator = function(p, i, n, c){ let principal = p; let interestRate = i; if(c > 740) { @@ -145,7 +145,7 @@ 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){ +let variableInterestRate = function(p, i, n){ for (let x = i - 0.02; x < i + 0.02; x += 0.005) { let principal = p; let rate = x.toFixed(3); @@ -163,11 +163,11 @@ function variableInterestRate(p, i, n){ let numerator = (principal * n1 * monthlyInterestRate) let denominator = (n1 - 1); let monthlyRate = (numerator / denominator); - let result = (Math.round(monthlyRate * 100) / 100).toFixed(0); + var result = (Math.round(monthlyRate * 100) / 100).toFixed(0); + return result; - - console.log(`${name}, with an intrest rate of ${interestRate} your monthly rate is ${result}`) + // console.log(`${name}, with an intrest rate of ${interestRate} your monthly rate is ${result}`) } } @@ -179,8 +179,16 @@ variableInterestRate(200000, 0.04, 30); /* 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 */ +let additionalFees = function(t, i, h) { + tax = t; + insurance = i; + hoa = h; + var feeResult = (tax + insurance + hoa); + return feeResult; +} - +additionalFees(95, 250, 200) +console.log(`Your total monthly spending is ${feeResult}`) /* 🏡 Build a calculator function that accepts `monthly payment` and `interest rate` and returns the maximum loan that a person could afford */ From 98e1aa12e0d314a9d2c301233ba95e44af013855 Mon Sep 17 00:00:00 2001 From: Trevor Locke Date: Sun, 18 Oct 2020 21:01:38 -0500 Subject: [PATCH 6/6] MVP + 2 Stretch finished --- index.js | 64 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index ab8d20ce..58801e73 100644 --- a/index.js +++ b/index.js @@ -102,6 +102,7 @@ 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. */ + let mortgageCalculator = function(p, i, n, c){ let principal = p; let interestRate = i; @@ -117,7 +118,7 @@ let mortgageCalculator = function(p, i, n, c){ let periods = (years * 12);let n1 = Math.pow ((1+ monthlyInterestRate), periods); let numerator = (principal * n1 * monthlyInterestRate) let denominator = (n1 - 1); - let monthlyRate = (numerator / denominator) + let monthlyRate = (numerator / denominator); let result = (Math.round(monthlyRate * 100) / 100).toFixed(2); @@ -127,7 +128,7 @@ let mortgageCalculator = function(p, i, n, c){ } mortgageCalculator(200000, 0.05, 30, 780) - +console.log(result) // 🏡 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. @@ -163,7 +164,7 @@ let variableInterestRate = function(p, i, n){ let numerator = (principal * n1 * monthlyInterestRate) let denominator = (n1 - 1); let monthlyRate = (numerator / denominator); - var result = (Math.round(monthlyRate * 100) / 100).toFixed(0); + let result = Number(Math.round(monthlyRate * 100) / 100).toFixed(0); return result; @@ -171,27 +172,66 @@ let variableInterestRate = function(p, i, n){ } } -variableInterestRate(200000, 0.04, 30); - +var variableResult = Number(variableInterestRate(200000, 0.04, 30)); +console.log(variableResult) // 🌟🌟🌟 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 */ +// let feeResult = ""; + + let additionalFees = function(t, i, h) { - tax = t; - insurance = i; - hoa = h; - var feeResult = (tax + insurance + hoa); - return feeResult; + let tax = t; + let insurance = i; + let hoa = h; + let feeResult = Number(tax + insurance + hoa); + console.log(`Your total cost is ${(feeResult + variableResult)}`); + + } additionalFees(95, 250, 200) -console.log(`Your total monthly spending is ${feeResult}`) -/* 🏡 Build a calculator function that accepts `monthly payment` and `interest rate` and returns the maximum loan that a person could afford */ +/* 🏡 Build a calculator function that accepts `monthly payment` and `interest rate` and returns the maximum loan that a person could afford */ +// let maxLoan = function(a, t){ + +function maxLoan(monthlyPayment, interestRate){ + let possiblePrinciple = 0; + let monthlyRate = 0; + do { + let monthlyRate = mortgageCalc(possiblePrinciple, interestRate); + console.log(monthlyRate); + if (monthlyRate >= monthlyPayment) { + return `Your max loan is ${possiblePrinciple}.`; + } else { + possiblePrinciple += 1; + } + } while (monthlyRate < monthlyPayment); + } + + function mortgageCalc(principal, interestRate) { + + let years = 30; + let monthlyInterestRate = (interestRate / 12); + let periods = (years * 12); + let n1 = Math.pow ((1+ monthlyInterestRate), periods); + let numerator = (principal * n1 * monthlyInterestRate); + let denominator = (n1 - 1); + let monthlyRate = (numerator / denominator); + monthlyRate = monthlyRate.toFixed(2); + + return monthlyRate; + + } + + var output = maxLoan(500, 0.05); + console.log(output); + +// console.log(`maxLoan is ${newResult}`); /* 🏡 Explore using `window.prompt()` to allow a user to input parameters in the browser */