From 3c78c0e5c24ec4de4f2c0e08630f48d546b11420 Mon Sep 17 00:00:00 2001 From: MADeveloper32 <68301699+MADeveloper32@users.noreply.github.com> Date: Sun, 18 Oct 2020 00:02:18 -0400 Subject: [PATCH 1/3] halfway into project --- index.js | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 667af155..d56255e9 100644 --- a/index.js +++ b/index.js @@ -3,8 +3,17 @@ // 🏡 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; +console.log(principal);} +{let interestRate = 0.05; +console.log(interestRate);} +{let years = 30; +console.log(years);} + +{const name = 'Mariam'; +console.log(name);} @@ -14,7 +23,13 @@ (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 interestRate = 0.05; + let monthlyInterestRate = interestRate / 12; + console.log(monthlyInterestRate);} +{let years = 30; + let periods = years * 12; +console.log(periods);} @@ -34,7 +49,15 @@ 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 p = (200000); + let i = (0.05); + let years = (30); + let n = (years * 12); + let n1 = (i * [1 + i]) ^ n; + let numerator = (p * n1 *); + let denominator = (n1 - 1); + let monthlyRate = (numerator / denominator); + console.log(monthlyRate);} @@ -43,8 +66,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" */ - - +//I wrote this here. +//function mortgageCalculator (){let ___=___; +//return ___;} +//console.log (mortgageCalculator); @@ -55,7 +80,9 @@ For example, mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64 */ - +//I wrote this here +//const mortgageCalculator = function (P, I, N){return 200000, 0.05, 30}; +//console.log(mortgageCalculator ()); From 9bff9e1dfe621b83f0124229e4fda8c64a0e79a7 Mon Sep 17 00:00:00 2001 From: MADeveloper32 <68301699+MADeveloper32@users.noreply.github.com> Date: Sun, 18 Oct 2020 18:48:52 -0400 Subject: [PATCH 2/3] still working on questions 4 through 6 --- index.js | 70 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 52 insertions(+), 18 deletions(-) diff --git a/index.js b/index.js index d56255e9..5f8c2140 100644 --- a/index.js +++ b/index.js @@ -50,26 +50,34 @@ 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 p = (200000); - let i = (0.05); - let years = (30); - let n = (years * 12); - let n1 = (i * [1 + i]) ^ n; - let numerator = (p * n1 *); - let denominator = (n1 - 1); - let monthlyRate = (numerator / denominator); - console.log(monthlyRate);} - - + let i = (0.05 / 12); + let n = (30 * 12); + let n1 = (1 + i)**n; + let numerator = [p * (n1 * i)]; + let denominator = (n1 - 1); + let monthlyRate = (numerator / denominator); + console.log(monthlyRate); +} // 🏡 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}" If your name is `Oscar` mortgageCalculator() should return "Oscar, your monthly rate is 1073.64" */ -//I wrote this here. -//function mortgageCalculator (){let ___=___; -//return ___;} -//console.log (mortgageCalculator); +function mortgageCalculator(){ + let p = (200000); + let i = (0.05 / 12); + let n = (30 * 12); + let n1 = (1 + i) ** n; + let numerator = [p * (n1 * i)]; + let denominator = (n1 - 1); + let monthlyRate = (numerator / denominator); + let name = 'Mariam, '; + let string = 'your monthly rate is $' + let sentence = (name + string + monthlyRate); + return sentence; +} +console.log(mortgageCalculator()); @@ -80,9 +88,17 @@ For example, mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64 */ -//I wrote this here -//const mortgageCalculator = function (P, I, N){return 200000, 0.05, 30}; -//console.log(mortgageCalculator ()); +var mortgageCalculator = function(P,I,N){ + let p = (200000); + let i = (0.05 / 12); + let n = (30 * 12); + let n1 = (1 + i) ** n; + let numerator = [p * (n1 * i)]; + let denominator = (n1 - 1); + let monthlyRate = (numerator / denominator); + console.log(monthlyRate); + return (P,I,N);} + console.log(mortgageCalculator(200000, 0.05, 30)); @@ -93,7 +109,25 @@ 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. */ - +/*var mortgageCalculator = function(P, I, N, creditScore){ + let creditScore= (<= 800); + let p = (200000); + let i = (0.05 / 12); + let n = (30 * 12); + let n1 = (1 + i) ** n; + let numerator = [p * (n1 * i)]; + let denominator = (n1 - 1); + let monthlyRate = (numerator / denominator); + console.log(monthlyRate); + return [P*[(1+I/12)**N]*(I/12)] / ([(1+I/12)**N]-1)}; +console.log(mortgageCalculator(200000, 0.05, 30)); +let ___=___; +let ___=___; +if (___=___); +{____=____}; +else if (___=___)_; +{_____=___} +else console.log{___};*/ From 21d8bb049f3dad1ec70c27cf7527ab6bfe73e279 Mon Sep 17 00:00:00 2001 From: MADeveloper32 <68301699+MADeveloper32@users.noreply.github.com> Date: Tue, 20 Oct 2020 22:39:14 -0400 Subject: [PATCH 3/3] completed project --- index.js | 87 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 43 insertions(+), 44 deletions(-) diff --git a/index.js b/index.js index 5f8c2140..0618f0c4 100644 --- a/index.js +++ b/index.js @@ -3,17 +3,17 @@ // 🏡 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; -console.log(principal);} +let principal = 200000; +console.log(principal); -{let interestRate = 0.05; -console.log(interestRate);} +let interestRate = 0.05; +console.log(interestRate); -{let years = 30; -console.log(years);} +let years = 30; +console.log(years); -{const name = 'Mariam'; -console.log(name);} +const name = 'Mariam'; +console.log(name); @@ -23,13 +23,12 @@ console.log(name);} (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 interestRate = 0.05; let monthlyInterestRate = interestRate / 12; - console.log(monthlyInterestRate);} + console.log(monthlyInterestRate); + -{let years = 30; let periods = years * 12; -console.log(periods);} +console.log(periods); @@ -49,35 +48,34 @@ 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 p = (200000); - let i = (0.05 / 12); - let n = (30 * 12); - let n1 = (1 + i)**n; - let numerator = [p * (n1 * i)]; + + + function calculator(P,I,N){ + let n1 = Math.pow(1 + I/12,periods); + let numerator = [P * (n1 * I/12)]; let denominator = (n1 - 1); - let monthlyRate = (numerator / denominator); + let monthlyRate = (numerator / denominator).toFixed(2); console.log(monthlyRate); -} + return monthlyRate; + } // 🏡 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}" If your name is `Oscar` mortgageCalculator() should return "Oscar, your monthly rate is 1073.64" */ -function mortgageCalculator(){ - let p = (200000); - let i = (0.05 / 12); - let n = (30 * 12); - let n1 = (1 + i) ** n; - let numerator = [p * (n1 * i)]; - let denominator = (n1 - 1); - let monthlyRate = (numerator / denominator); - let name = 'Mariam, '; - let string = 'your monthly rate is $' - let sentence = (name + string + monthlyRate); - return sentence; + + +function mortgageCalculator(P,I,N,creditScore){ + if (creditScore>740){ + I=I-0.05 + } + rate = calculator(P,I,N) + let string = ', your monthly rate is $' + teststring=`${name}, your monthly rate is $${rate}` + return teststring; } -console.log(mortgageCalculator()); +console.log(mortgageCalculator(200000, 0.05, 30)); @@ -88,17 +86,6 @@ For example, mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64 */ -var mortgageCalculator = function(P,I,N){ - let p = (200000); - let i = (0.05 / 12); - let n = (30 * 12); - let n1 = (1 + i) ** n; - let numerator = [p * (n1 * i)]; - let denominator = (n1 - 1); - let monthlyRate = (numerator / denominator); - console.log(monthlyRate); - return (P,I,N);} - console.log(mortgageCalculator(200000, 0.05, 30)); @@ -147,7 +134,19 @@ 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){ + /*loop that increases I by .5% ten times*/ + /*inside the loop run lines 140 through 143*/ + I=Math.round((I-0.02)*1000)/1000; + for (let i = 0; i < 10; i++){ + I = Math.round((I + 0.005)*1000)/1000; + console.log(`logging I: ${I}`) + rate = calculator(P,I,N) + teststring=`${name}, with an interest rate of ${I}, your monthly rate is $${rate}` + console.log(teststring); +} +} +console.log(variableInterestRate(200000, 0.04, 30)); // 🌟🌟🌟 STRETCH 🌟🌟🌟//