From eb0b7851e3b1f3b62e1063a77e26837f9fb3bb45 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 18 Oct 2020 20:02:53 -0400 Subject: [PATCH 1/3] step 3 --- index.html | 2 +- index.js | 32 +++++++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index b458c1ff..1b730e72 100644 --- a/index.html +++ b/index.html @@ -7,7 +7,7 @@

Open up the console to check your work!

- + diff --git a/index.js b/index.js index 667af155..06466306 100644 --- a/index.js +++ b/index.js @@ -3,23 +3,30 @@ // 🏡 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 = .05; +let years = 30; + +let name = "nicholas-torres"; // 🏡 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. +/* 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. +(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; // 🏡 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 ] @@ -27,7 +34,7 @@ Hint: while these calculations can be done in one line, it might be helpful to c (1) Create a variable called n1 and set it equal to (1 + monthlyInterestRate )^N (2) Create a variable called numerator and set it equal to p * n1 * monthlyInterestRate -(3) Create a variable called denominator and set it equal to n1 - 1 +(3) Create a variable called denominator and set it equal to n1 - 1 (4) 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! @@ -36,6 +43,17 @@ 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,6 +62,10 @@ 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(){ + + console.log(name + ", your monthly rate is $" + monthlyRate); +} @@ -64,7 +86,7 @@ mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64 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. +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. */ From dba565cbb19b1f43a2cbe4b5cb2b45d971387844 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 18 Oct 2020 20:26:10 -0400 Subject: [PATCH 2/3] step 5 --- index.js | 86 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 73 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index 06466306..fd30aafa 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,15 @@ // 🌟🌟🌟 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. -*/ -let principal = 200000; -let interestRate = .05; -let years = 30; + +let principal = P; +let interestRate = I; +let years = N; let name = "nicholas-torres"; @@ -18,7 +22,7 @@ let name = "nicholas-torres"; (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; @@ -40,12 +44,12 @@ 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 -*/ + let n1 = Math.pow(1 + monthlyInterestRate, periods); -let numerator = (principal * n1 * monthlyInterestRate); +let numerator = (P * n1 * monthlyInterestRate); let denominator = (n1 - 1); @@ -62,11 +66,6 @@ console.log(monthlyRate); If your name is `Oscar` mortgageCalculator() should return "Oscar, your monthly rate is 1073.64" */ -function mortgageCalculator(){ - - console.log(name + ", your monthly rate is $" + monthlyRate); -} - @@ -75,7 +74,34 @@ function mortgageCalculator(){ 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 = "nicholas-torres"; + + let monthlyInterestRate = interestRate / 12; + let periods = years * 12; + + let n1 = Math.pow(1 + monthlyInterestRate, periods); + + let numerator = (P * n1 * monthlyInterestRate); + + let denominator = (n1 - 1); + + let monthlyRate = numerator/denominator; + + + console.log(name + ", your monthly rate is $" + monthlyRate); +} + +mortgageCalculator(200000, .05, 30); + @@ -90,6 +116,40 @@ Hint: To drop an interest rate by 5% you can take monthlyRate and multiply it by */ +function mortgageCalculator(P , I , N, creditScore){ + + if (creditScore > 740){ + var interestRate = I * .95; + } + else if (creditScore < 660){ + var interestRate = I * 1.05; + } + + else if (creditScore < 740 && creditScore > 660){ + var interestRate = I; + } + + let years = N; + + let name = "nicholas-torres"; + + let monthlyInterestRate = interestRate / 12; + let periods = years * 12; + + let n1 = Math.pow(1 + monthlyInterestRate, periods); + + let numerator = (P * n1 * monthlyInterestRate); + + let denominator = (n1 - 1); + + let monthlyRate = numerator/denominator; + + + console.log(name + ", your monthly rate is $" + monthlyRate); +} + +mortgageCalculator(200000, .05, 30, 500); + // 🏡 Task 6: Loops From 36fcbb004406d1489d015c68626b4be0052cdcdd Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 18 Oct 2020 21:21:30 -0400 Subject: [PATCH 3/3] final --- index.js | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index fd30aafa..8eafaad6 100644 --- a/index.js +++ b/index.js @@ -113,7 +113,7 @@ mortgageCalculator(200000, .05, 30); 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 mortgageCalculator(P , I , N, creditScore){ @@ -168,8 +168,44 @@ 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 = I - .02; + + + for (var i = 0; i < 10; ++i){ + + + + let variableInterest = i * .005; + interestRate = variableInterest + I; + + + let years = N; + + let name = "nicholas-torres"; + + + + let monthlyInterestRate = interestRate / 12; + let periods = years * 12; + + let n1 = Math.pow(1 + monthlyInterestRate, periods); + + let numerator = (P * n1 * monthlyInterestRate); + + let denominator = (n1 - 1); + + let monthlyRate = numerator/denominator; + + + console.log(name + ", with an interest rate of " + interestRate + ", your monthly rate is " + monthlyRate); + + } +} +variableInterestRate(200000, .04, 30); // 🌟🌟🌟 STRETCH 🌟🌟🌟//