From 81e81b56bb204a39dab8168a92e00e5cdc45c3da Mon Sep 17 00:00:00 2001 From: Jessica Chu Date: Thu, 15 Oct 2020 23:03:39 -0400 Subject: [PATCH 1/3] Did tasks 1-3 --- index.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/index.js b/index.js index 667af155..dcb88fa1 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,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; +const name = 'Jessica'; @@ -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,12 @@ 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 */ +const n1 = Math.pow((1 + monthlyInterestRate ) ,periods); +const numerator = principal * n1 * monthlyInterestRate; +const denominator = n1 - 1; +let monthlyRate = numerator/denominator; +console.log(monthlyRate); // 🏡 Task 3: Function @@ -44,6 +55,23 @@ 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 + // const name = "Jessica" + // let monthlyInterestRate = interestRate/12 + // let periods = years*12 + // const n1 = Math.pow((1 + monthlyInterestRate), periods) + // const numerator = principal * n1 * monthlyInterestRate + // const denominator = n1 - 1 + // let monthlyRate = numerator / denominator + console.log(name + ", your monthly rate is " + monthlyRate); +} + +mortgageCalculator(); + From 9e718c45f61e2e9abab9546453e1c1a4b22244ef Mon Sep 17 00:00:00 2001 From: Jessica Chu Date: Sat, 17 Oct 2020 01:10:11 -0400 Subject: [PATCH 2/3] found an answer for task 6 using google. Unfortunately the git commit -m "found an answer for task 6 with google --- index.js | 87 +++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 67 insertions(+), 20 deletions(-) diff --git a/index.js b/index.js index dcb88fa1..41c41104 100644 --- a/index.js +++ b/index.js @@ -46,7 +46,7 @@ const numerator = principal * n1 * monthlyInterestRate; const denominator = n1 - 1; let monthlyRate = numerator/denominator; -console.log(monthlyRate); +console.log("$" + monthlyRate); // 🏡 Task 3: Function @@ -55,22 +55,22 @@ console.log(monthlyRate); 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 - // const name = "Jessica" - // let monthlyInterestRate = interestRate/12 - // let periods = years*12 - // const n1 = Math.pow((1 + monthlyInterestRate), periods) - // const numerator = principal * n1 * monthlyInterestRate - // const denominator = n1 - 1 - // let monthlyRate = numerator / denominator - console.log(name + ", your monthly rate is " + monthlyRate); -} +// function mortgageCalculator() +// { +// let principal = 200000; +// let interestRate = 0.05; +// let years = 30; +// const name = "Jessica"; +// let monthlyInterestRate = interestRate/12; +// let periods = years*12; +// const n1 = Math.pow((1 + monthlyInterestRate), periods); +// const numerator = principal * n1 * monthlyInterestRate; +// const denominator = n1 - 1; +// let monthlyRate = numerator / denominator; +// console.log(name + ", your monthly rate is " + monthlyRate); +// } -mortgageCalculator(); +// mortgageCalculator(); @@ -82,10 +82,18 @@ mortgageCalculator(); For example, mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64 */ - - - - +// function mortgageCalculator(principal, interestRate, years){ +// const name = "Jessica"; +// let monthlyInterestRate = interestRate/12; +// let periods = years*12; +// const n1 = Math.pow((1 + monthlyInterestRate), periods); +// const numerator = principal * n1 * monthlyInterestRate; +// const denominator = n1 - 1; +// let monthlyRate = numerator / denominator; +// console.log(name + ", your monthly rate is " + monthlyRate); +// } + +// 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). @@ -94,7 +102,27 @@ 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(principal, interestRate, years, creditScore){ +// const name = "Jessica"; +// let monthlyInterestRate = interestRate/12; +// let periods = years*12; +// const n1 = Math.pow((1 + monthlyInterestRate), periods); +// const numerator = principal * n1 * monthlyInterestRate; +// const denominator = n1 - 1; +// let monthlyRate = numerator / denominator; + +// if (creditScore > 740){ +// monthlyRate = (monthlyRate * 0.95); +// } else if (creditScore < 660){ +// monthlyRate = (monthlyRate * 1.05); +// } else if (creditScore <= 740 && creditScore >= 660){ +// monthlyRate = (monthlyRate); +// } +// console.log(name + ", your monthly rate is " + monthlyRate); +// } + +// mortgageCalculator(200000, 0.05, 30, 750); @@ -114,6 +142,25 @@ 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, interestRate, years){ + const name = "Jessica"; + const count= 10; + let monthlyInterestRate = interestRate/12; + let periods = years*12; + const n1 = (1 + monthlyInterestRate) ** periods; + const numerator = principal * n1 * monthlyInterestRate; + const denominator = n1 - 1; + let monthlyRate = numerator / denominator; + + + for (let interestRate = .02; interestRate <= .06; interestRate += .005) { + let monthlyRate = principal * interestRate / 12 * (Math.pow(1 + interestRate / 12, years * 12)) / (Math.pow(1 + interestRate / 12, years * 12) - 1); + console.log(name + ", with an interest rate of " + interestRate.toFixed(3) + ", your monthly interest rate is $" + Math.round(monthlyRate + interestRate)); + } + +} +variableInterestRate(200000, 0.04, 30); + From 315757e5da1ce7f15b9f411ef7d80b6c3925eb98 Mon Sep 17 00:00:00 2001 From: Jessica Chu Date: Sat, 17 Oct 2020 18:52:46 -0400 Subject: [PATCH 3/3] took one thing out of my task 6 console.log --- index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/index.js b/index.js index 41c41104..d0501d09 100644 --- a/index.js +++ b/index.js @@ -155,7 +155,7 @@ function variableInterestRate(principal, interestRate, years){ for (let interestRate = .02; interestRate <= .06; interestRate += .005) { let monthlyRate = principal * interestRate / 12 * (Math.pow(1 + interestRate / 12, years * 12)) / (Math.pow(1 + interestRate / 12, years * 12) - 1); - console.log(name + ", with an interest rate of " + interestRate.toFixed(3) + ", your monthly interest rate is $" + Math.round(monthlyRate + interestRate)); + console.log(name + ", with an interest rate of " + interestRate.toFixed(3) + ", your monthly interest rate is $" + Math.round(monthlyRate)); } } @@ -163,7 +163,6 @@ 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 */