From 29efbcdeed050fe27560487f9f120263e71e1ee4 Mon Sep 17 00:00:00 2001 From: Ethan Karp Date: Sat, 17 Oct 2020 20:37:21 -0600 Subject: [PATCH 1/3] completed tasks 1-4 --- index.js | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 667af155..11908d06 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,8 @@ // 🏡 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, interestRate = 0.05, years = 30; +let name = 'Ethan' @@ -15,7 +16,8 @@ (2) 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 @@ -35,7 +37,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 @@ -44,9 +50,16 @@ 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 n1 = Math.pow((1 + monthlyInterestRate), periods); + let numerator = principal * n1 * monthlyInterestRate; + let denominator = n1 - 1; + let monthlyRate = numerator / denominator; + return console.log(name + ', your monthly rate is $' + monthlyRate); +} - +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. @@ -55,8 +68,16 @@ For example, mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64 */ +function mortgageCalculator(P, I, N) { + let n1 = Math.pow((1 + (I/12)), (N*12)); + let numerator = P * n1 * monthlyInterestRate; + let denominator = n1 - 1; + let monthlyRate = numerator / denominator; + return console.log(name + ', your monthly rate is $' + monthlyRate); +} +mortgageCalculator(200000, 0.05, 30); // 🏡 Task 5: Conditionals From 2d91581114e3e5998c0fbd7bc5d99cd4ec4ad63f Mon Sep 17 00:00:00 2001 From: Ethan Karp Date: Sat, 17 Oct 2020 20:58:47 -0600 Subject: [PATCH 2/3] finished task 5 --- index.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/index.js b/index.js index 11908d06..41408532 100644 --- a/index.js +++ b/index.js @@ -88,7 +88,24 @@ 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, creditScore) { + let n1 = Math.pow((1 + (I/12)), (N*12)); + let numerator = P * n1 * monthlyInterestRate; + let denominator = n1 - 1; + let monthlyRate = numerator / denominator; + + if (creditScore > 740) { + monthlyRate *= 0.95; + } else if (creditScore < 660) { + monthlyRate *= 1.05; + } else { + monthlyRate = numerator / denominator; + } + + return console.log(name + ', your monthly rate is $' + monthlyRate); +} +mortgageCalculator(200000, 0.05, 30, 740); // 🏡 Task 6: Loops From dfaed4de6ff1c1e36e7296859a3ee41562767a19 Mon Sep 17 00:00:00 2001 From: Ethan Karp Date: Sun, 18 Oct 2020 12:12:10 -0600 Subject: [PATCH 3/3] finished task 6 --- index.js | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 41408532..c320b62f 100644 --- a/index.js +++ b/index.js @@ -41,7 +41,7 @@ let n1 = Math.pow((1 + monthlyInterestRate), periods); let numerator = principal * n1 * monthlyInterestRate; let denominator = n1 - 1; let monthlyRate = numerator / denominator; -console.log(monthlyRate); +console.log(monthlyRate.toFixed(2)); // 🏡 Task 3: Function @@ -56,7 +56,7 @@ function mortgageCalculator() { let denominator = n1 - 1; let monthlyRate = numerator / denominator; - return console.log(name + ', your monthly rate is $' + monthlyRate); + return console.log(name + ', your monthly rate is $' + monthlyRate.toFixed(2)); } mortgageCalculator(); @@ -68,16 +68,16 @@ For example, mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64 */ -function mortgageCalculator(P, I, N) { +function mortgageCalculator2(P, I, N) { let n1 = Math.pow((1 + (I/12)), (N*12)); - let numerator = P * n1 * monthlyInterestRate; + let numerator = P * n1 * (I/12); let denominator = n1 - 1; let monthlyRate = numerator / denominator; - return console.log(name + ', your monthly rate is $' + monthlyRate); + return console.log(name + ', your monthly rate is $' + monthlyRate.toFixed(2)); } -mortgageCalculator(200000, 0.05, 30); +mortgageCalculator2(200000, 0.05, 30); // 🏡 Task 5: Conditionals @@ -88,9 +88,9 @@ 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, creditScore) { +function mortgageCalculator3(P, I, N, creditScore) { let n1 = Math.pow((1 + (I/12)), (N*12)); - let numerator = P * n1 * monthlyInterestRate; + let numerator = P * n1 * (I/12); let denominator = n1 - 1; let monthlyRate = numerator / denominator; @@ -102,10 +102,10 @@ function mortgageCalculator(P, I, N, creditScore) { monthlyRate = numerator / denominator; } - return console.log(name + ', your monthly rate is $' + monthlyRate); + return console.log(name + ', your monthly rate is $' + monthlyRate.toFixed(2)); } -mortgageCalculator(200000, 0.05, 30, 740); +mortgageCalculator3(200000, 0.05, 30, 740); // 🏡 Task 6: Loops @@ -124,8 +124,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(P, I, N) { + I -= 0.025; + for (let i = 0; i < 10; i++) { + + I += 0.005; + + let n1 = Math.pow((1 + (I/12)), (N*12)); + let numerator = P * n1 * (I/12); + let denominator = n1 - 1; + let monthlyRate = numerator / denominator; + + console.log(name + ', with an interest rate of ' + I.toFixed(3) + ', your monthly rate is $' + Math.round(monthlyRate)); + + } +} + +variableInterestRate(200000, 0.04, 30); // 🌟🌟🌟 STRETCH 🌟🌟🌟//