From 9f2388397f93d6f4c9c370a2e6e93455c6f93937 Mon Sep 17 00:00:00 2001 From: Saeed Khan Date: Fri, 16 Oct 2020 21:40:58 -0600 Subject: [PATCH 1/4] I added the variables for principal, interest rate, and years --- index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 667af155..29109d88 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,9 @@ /* 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 = principal(200000); +let interest = interest(0.05); +let years = years(30); @@ -12,6 +14,7 @@ /* 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. + (2) Create another variable called `periods` and give it the value of years*12. */ From 78fb42084ed3c09b2ca9c744995ddb48b21aeeaa Mon Sep 17 00:00:00 2001 From: Saeed Khan Date: Fri, 16 Oct 2020 23:38:52 -0600 Subject: [PATCH 2/4] I completed task 3 by returning a string that calculated the monthly mortage rate. --- index.js | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 29109d88..4a15816a 100644 --- a/index.js +++ b/index.js @@ -4,9 +4,11 @@ /* 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 = principal(200000); -let interest = interest(0.05); -let years = years(30); +let principal = 200000; +let interest = 0.05; +let years = 30; +let name = 'Oscar'; + @@ -18,6 +20,12 @@ let years = years(30); (2) Create another variable called `periods` and give it the value of years*12. */ +let monthlyInterestRate = (interest / 12); { + console.log(monthlyInterestRate); +} +let periods = (years * 12); { + console.log(periods); +} @@ -38,7 +46,22 @@ 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 = (1 + monthlyInterestRate)**periods; { + console.log(n1); +} + +const numerator = (principal * n1 * monthlyInterestRate); { + console.log(numerator); +} + +const denominator = (n1 - 1); { + console.log(denominator); +} +let monthlyRate = (numerator / denominator); { + + console.log(monthlyRate); +} // 🏡 Task 3: Function @@ -46,7 +69,32 @@ 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(name){ + +const n1 = (1 + monthlyInterestRate)**periods; { + console.log(n1); +} + +const numerator = (principal * n1 * monthlyInterestRate); { + console.log(numerator); +} + +const denominator = (n1 - 1); { + console.log(denominator); +} + +let monthlyRate = (numerator / denominator); { + + console.log(monthlyRate); + return `${name}, your monthly rate is ${monthlyRate}`; +} +} +mortgageCalculator('Oscar'); { + + +} +var output = mortgageCalculator('Oscar'); +console.log(output); From 196eadb1272170fb7a49717ddccd001c95a1a739 Mon Sep 17 00:00:00 2001 From: Saeed Khan Date: Sat, 17 Oct 2020 20:00:12 -0600 Subject: [PATCH 3/4] Completed task 4, and 5 --- index.js | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/index.js b/index.js index 4a15816a..956d19c0 100644 --- a/index.js +++ b/index.js @@ -8,6 +8,7 @@ let principal = 200000; let interest = 0.05; let years = 30; let name = 'Oscar'; +let creditScore = 660; @@ -107,6 +108,32 @@ mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64 */ +function mortgageCalculator(principal, interest, periods){ + + const n1 = (1 + monthlyInterestRate)**periods; { + console.log(n1); + } + + const numerator = (principal * n1 * monthlyInterestRate); { + console.log(numerator); + } + + const denominator = (n1 - 1); { + console.log(denominator); + } + + let monthlyRate = (numerator / denominator); { + + console.log(monthlyRate); + return `${name}, your monthly rate is ${monthlyRate}`; + } + } + mortgageCalculator(principal, interest, periods); { + + + } + var output = mortgageCalculator(principal, interest, periods); + console.log(output); @@ -118,6 +145,39 @@ 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, interest, periods){ + + const n1 = (1 + monthlyInterestRate)**periods; { + console.log(n1); + } + + const numerator = (principal * n1 * monthlyInterestRate); { + console.log(numerator); + } + + const denominator = (n1 - 1); { + console.log(denominator); + } + + let monthlyRate = (numerator / denominator); { + } + if (creditScore < 740) { + monthlyRate = (monthlyRate * 0.95); + return `${name}, your monthly rate is ${monthlyRate}`; + } else if (creditScore > 660) { + monthlyRate = (monthlyRate * 1.05); + return `${name}, your monthly rate is ${monthlyRate}`; + + } + } + mortgageCalculator(principal, interest, periods); { + + + } + var output = mortgageCalculator(principal, interest, periods); + console.log(output); + + From 84417cfe21d7b25c7d13d2c5e2dbfe77aabf26b3 Mon Sep 17 00:00:00 2001 From: Saeed Khan Date: Sun, 18 Oct 2020 12:07:01 -0600 Subject: [PATCH 4/4] I completed all tasks 1-6 --- index.js | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 956d19c0..d3db3d92 100644 --- a/index.js +++ b/index.js @@ -5,10 +5,10 @@ */ let principal = 200000; -let interest = 0.05; +let interest = 0.04; let years = 30; let name = 'Oscar'; -let creditScore = 660; +let creditScore = 720; @@ -145,7 +145,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(principal, interest, periods){ + function mortgageCalculator(principal, interest, periods){ const n1 = (1 + monthlyInterestRate)**periods; { console.log(n1); @@ -161,14 +161,19 @@ function mortgageCalculator(principal, interest, periods){ let monthlyRate = (numerator / denominator); { } - if (creditScore < 740) { + if (creditScore > 740) { monthlyRate = (monthlyRate * 0.95); return `${name}, your monthly rate is ${monthlyRate}`; - } else if (creditScore > 660) { + } else if (creditScore < 660) { monthlyRate = (monthlyRate * 1.05); return `${name}, your monthly rate is ${monthlyRate}`; } + else if (creditScore >= 660 && creditScore <= 40) { + monthlyRate = (monthlyRate * 1.00); + + } + return `${name}, your monthly rate is ${monthlyRate}`; } mortgageCalculator(principal, interest, periods); { @@ -198,6 +203,34 @@ For example, variableInterestRate(200000, 0.04, 30) should console.log: */ +function variableInterestRate(principal, interest, years, name){ + + + for (let i = interest - 0.02; i <= interest + 0.02; i += 0.005) { + + const monthlyInterestRate = i / 12; + + const periods = years * 12; + + const n1 = (1 + monthlyInterestRate) ** periods; + + const numerator = principal * (n1 * monthlyInterestRate); + + const denominator = (n1 - 1); + + let monthlyRate1 = numerator/denominator; + + console.log(`${name}, with an interest rate of ${i}, your monthly rate is $${Math.round(monthlyRate1)}`); + + const mynumber = 10; + } + +} + +variableInterestRate(200000,0.04,30, 'John'); + + + // 🌟🌟🌟 STRETCH 🌟🌟🌟//