From 4eea08ac6551da78e575f2cfbf035c3450a4d6d3 Mon Sep 17 00:00:00 2001 From: Tony Miller <70006926+artofmayhem@users.noreply.github.com> Date: Fri, 16 Oct 2020 09:53:58 -1000 Subject: [PATCH 1/5] tasks 1-3 completed --- index.js | 59 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/index.js b/index.js index 667af155..30737e39 100644 --- a/index.js +++ b/index.js @@ -1,29 +1,27 @@ -// 🌟🌟🌟 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 principle = 200000; +const interestRate = 0.05; +const years = 30; +let name = 'Tony Miller'; // 🏡 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. (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 ] +//M = principle [ interestRate ( 1 + interestRate )^periods ] / [ ( 1 + interestRate )^periods - 1 ] -Hint: while these calculations can be done in one line, it might be helpful to create seperate variables to hold parts of your equation. That might look like this: +//M = P [ I ( 1 + I )^N ] / [ ( 1 + I )^N – 1 ] +/*Hint: while these calculations can be done in one line, it might be helpful to create seperate variables to hold parts of your equation. That might look like this: (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 @@ -35,7 +33,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 = principle * n1 * monthlyInterestRate; +let denominator = n1 - 1; +let monthlyRate = numerator / denominator; +console.log(monthlyRate); // 🏡 Task 3: Function @@ -43,10 +45,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(name principle) +{ + let principle = 200000; + const interestRate = 0.05; + const years = 30; + let name = 'Tony Miller'; + let monthlyInterestRate = interestRate / 12; + let periods = years * 12; + let n1 = Math.pow((1 + monthlyInterestRate), periods); + let numerator = principle * n1 * monthlyInterestRate; + let denominator = n1 - 1; + let monthlyRate = numerator / denominator; + + return(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. @@ -56,8 +71,13 @@ mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64 */ +P = principle; +I = interestRate; +N = periods + +mortgageCalculator(P, I, N); // 🏡 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). @@ -66,6 +86,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. */ +if creditScore > 740 { + I - .005; +} @@ -84,7 +107,7 @@ For example, variableInterestRate(200000, 0.04, 30) should console.log: "{Name}, with an interest rate of 0.05, your monthly rate is $1074" "{Name}, with an interest rate of 0.055, your monthly rate is $1136" "{Name}, with an interest rate of 0.06, your monthly rate is $1199" -*/ +*/ From a30a2bb180840575e77e2082dd30e30b9cf84445 Mon Sep 17 00:00:00 2001 From: Tony Miller <70006926+artofmayhem@users.noreply.github.com> Date: Fri, 16 Oct 2020 16:04:42 -1000 Subject: [PATCH 2/5] tasks 1-5 complete working mortgage calculator. task six for loop showing 10 interests rates is done to: finish variableInterestRate equation --- index.js | 119 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 96 insertions(+), 23 deletions(-) diff --git a/index.js b/index.js index 30737e39..1b02d1c7 100644 --- a/index.js +++ b/index.js @@ -1,9 +1,9 @@ // 🏡 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 principle = 200000; -const interestRate = 0.05; -const years = 30; +let principal = 200000; +let interestRate = 0.05; +let years = 30; let name = 'Tony Miller'; // 🏡 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. @@ -14,7 +14,6 @@ let name = 'Tony Miller'; 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. */ @@ -34,10 +33,10 @@ When your math is correct, monthlyRate will equal 1073.64 */ let n1 = Math.pow((1 + monthlyInterestRate), periods); -let numerator = principle * n1 * monthlyInterestRate; +let numerator = principal * n1 * monthlyInterestRate; let denominator = n1 - 1; let monthlyRate = numerator / denominator; -console.log(monthlyRate); +//console.log(monthlyRate); // 🏡 Task 3: Function @@ -45,23 +44,24 @@ console.log(monthlyRate); If your name is `Oscar` mortgageCalculator() should return "Oscar, your monthly rate is 1073.64" */ -function mortgageCalculator(name principle) +function mortgageCalculator(name, principle) { - let principle = 200000; - const interestRate = 0.05; - const years = 30; - let name = 'Tony Miller'; + //let principal = 200000; + let interestRate = 0.05; + let years = 30; + //let name = 'Tony'; let monthlyInterestRate = interestRate / 12; let periods = years * 12; let n1 = Math.pow((1 + monthlyInterestRate), periods); - let numerator = principle * n1 * monthlyInterestRate; - let denominator = n1 - 1; - let monthlyRate = numerator / denominator; + let numerator = principle * n1 * monthlyInterestRate; + let denominator = n1 - 1; + let monthlyRate = numerator / denominator; - return(name + ', your monthly rate is ' + monthlyRate); + return `${name}, your monthly rate is ${monthlyRate}`; } +//var output = mortgageCalculator('oscar', 200000); +//console.log(output); -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. @@ -70,25 +70,66 @@ For example, mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64 */ +function mortgageCalculator(name, principle, interestRate, years) +{ + //let principal = 200000; + //let interestRate = 0.05; + //let years = 30; + //let name = 'Tony'; + let monthlyInterestRate = interestRate / 12; + let periods = years * 12; + let n1 = Math.pow((1 + monthlyInterestRate), periods); + let numerator = principle * n1 * monthlyInterestRate; + let denominator = n1 - 1; + let monthlyRate = numerator / denominator; + + return `${name}, your monthly rate is ${monthlyRate}`; +} +//var output = mortgageCalculator('oscar', 200000); +//console.log(output); + + -P = principle; -I = interestRate; -N = periods -mortgageCalculator(P, I, N); // 🏡 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). 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.05. Similarly, to increase an interest rate by 5% you'd do monthlyRate * 1.05. */ -if creditScore > 740 { - I - .005; + +function mortgageCalculator(name, principle, interestRate, years, creditScore) +{ + //let principal = 200000; + //let interestRate = 0.05; + //let years = 30; + //let name = 'Tony'; + let monthlyInterestRate = interestRate / 12; + let periods = years * 12; + + if (creditScore > 740) { + monthlyInterestRate = monthlyInterestRate * 0.95; + + } else if (creditScore < 600) { + monthlyInterestRate = monthlyInterestRate * 1.05; + + } else if (creditScore >= 600 && creditScore <= 740) { + + } + let n1 = Math.pow((1 + monthlyInterestRate), periods); + let numerator = principle * n1 * monthlyInterestRate; + let denominator = n1 - 1; + let monthlyRate = numerator / denominator; + + + return `${name}, your monthly rate is ${monthlyRate}`; } +var output = mortgageCalculator('oscar', 200000, 0.05, 30, 800); +//console.log(output); @@ -108,7 +149,39 @@ For example, variableInterestRate(200000, 0.04, 30) should console.log: "{Name}, with an interest rate of 0.055, your monthly rate is $1136" "{Name}, with an interest rate of 0.06, your monthly rate is $1199" */ +function variableInterestRate() +{} + for (let i = 0; i < 10; i += 1) + { + function mortgageCalculator(name, principle, interestRate, years, creditScore) + { + //let principal = 200000; + //let interestRate = 0.05; + //let years = 30; + //let name = 'Tony'; + let monthlyInterestRate = interestRate / 12; + let periods = years * 12; + + if (creditScore > 740) { + monthlyInterestRate = monthlyInterestRate * 0.95; + + } else if (creditScore < 600) { + monthlyInterestRate = monthlyInterestRate * 1.05; + + } else if (creditScore >= 600 && creditScore <= 740) { + + } + let n1 = Math.pow((1 + monthlyInterestRate), periods); + let numerator = principle * n1 * monthlyInterestRate; + let denominator = n1 - 1; + let monthlyRate = numerator / denominator; + + return `${name}, your monthly rate is ${monthlyRate}`; + } + var output = mortgageCalculator('oscar', 200000, 0.05, 30, 800); + console.log(output); + } From 6cae314f4e9417a052c1f8cb82feb94ffbf92aa1 Mon Sep 17 00:00:00 2001 From: Tony Miller <70006926+artofmayhem@users.noreply.github.com> Date: Sat, 17 Oct 2020 12:47:28 -1000 Subject: [PATCH 3/5] Adjustments to task 6 introduced rounders to shorten variableInterest and monthly rate --- index.js | 54 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index 1b02d1c7..cd4947df 100644 --- a/index.js +++ b/index.js @@ -149,19 +149,20 @@ For example, variableInterestRate(200000, 0.04, 30) should console.log: "{Name}, with an interest rate of 0.055, your monthly rate is $1136" "{Name}, with an interest rate of 0.06, your monthly rate is $1199" */ + function variableInterestRate() -{} - for (let i = 0; i < 10; i += 1) +{ + +//for loop engine that turns function over 10 times + for (let i = 0; i < 10; i += 1) { function mortgageCalculator(name, principle, interestRate, years, creditScore) { - //let principal = 200000; - //let interestRate = 0.05; - //let years = 30; - //let name = 'Tony'; +//variables to spread input interest rate and years over 12 months let monthlyInterestRate = interestRate / 12; let periods = years * 12; - + +//credit score adjustment loop if (creditScore > 740) { monthlyInterestRate = monthlyInterestRate * 0.95; @@ -169,19 +170,41 @@ function variableInterestRate() monthlyInterestRate = monthlyInterestRate * 1.05; } else if (creditScore >= 600 && creditScore <= 740) { - + // No adjustment placeholder only } - let n1 = Math.pow((1 + monthlyInterestRate), periods); - let numerator = principle * n1 * monthlyInterestRate; - let denominator = n1 - 1; - let monthlyRate = numerator / denominator; +//formula calculation + let n1 = Math.pow((1 + monthlyInterestRate), periods); + let numerator = (principle * n1 * monthlyInterestRate); + let denominator = (n1 - 1); + let monthlyRate = (numerator / denominator); + +//creates bottom of the variable interest rate progression + let variableInterestRate = interestRate - 0.02; + +//Rounders + roundedVariableInterest = variableInterestRate.toFixed(3); + roundedMonthlyRate = monthlyRate.toFixed(2); + +//data return + return `${name}, with an interest rate of ${roundedVariableInterest}, your monthly rate is ${roundedMonthlyRate}`; + +//adds and equalizes variableInterestRate with 0.005 - return `${name}, your monthly rate is ${monthlyRate}`; - } - var output = mortgageCalculator('oscar', 200000, 0.05, 30, 800); + interestRate += 0.005; + } +// output + var output = mortgageCalculator('Oscar', 200000, 0.05, 30, 530); console.log(output); } +} +//function call to execute program + +variableInterestRate(); + + + + @@ -199,3 +222,4 @@ function variableInterestRate() /* 🏡 Refactor your `variableInterestRate()` function to accept an array of interest rates (make sure to copy and paste as to not lose your work!) */ + From 4ef01e71782a8c75cc0fd373c06f64f80be34704 Mon Sep 17 00:00:00 2001 From: Tony Miller <70006926+artofmayhem@users.noreply.github.com> Date: Sat, 17 Oct 2020 12:54:49 -1000 Subject: [PATCH 4/5] Update index.js --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index cd4947df..919f79cf 100644 --- a/index.js +++ b/index.js @@ -189,7 +189,7 @@ function variableInterestRate() //data return return `${name}, with an interest rate of ${roundedVariableInterest}, your monthly rate is ${roundedMonthlyRate}`; -//adds and equalizes variableInterestRate with 0.005 +//adds and equalizes interestRate with 0.005 interestRate += 0.005; } From 1ca4fdaa6a806c5efe7e9c494de43d33b13f3a99 Mon Sep 17 00:00:00 2001 From: Tony Miller <70006926+artofmayhem@users.noreply.github.com> Date: Sun, 18 Oct 2020 16:59:49 -1000 Subject: [PATCH 5/5] final product task 6 finished --- index.js | 64 +++++++++++++------------------------------------------- 1 file changed, 15 insertions(+), 49 deletions(-) diff --git a/index.js b/index.js index 919f79cf..ecb3982c 100644 --- a/index.js +++ b/index.js @@ -149,61 +149,27 @@ For example, variableInterestRate(200000, 0.04, 30) should console.log: "{Name}, with an interest rate of 0.055, your monthly rate is $1136" "{Name}, with an interest rate of 0.06, your monthly rate is $1199" */ +const variableInterestRate = function (name, principal, interestRate, years) { -function variableInterestRate() -{ - -//for loop engine that turns function over 10 times - for (let i = 0; i < 10; i += 1) - { - function mortgageCalculator(name, principle, interestRate, years, creditScore) - { -//variables to spread input interest rate and years over 12 months - let monthlyInterestRate = interestRate / 12; - let periods = years * 12; + //for loop engine using interestRate as the counter + for (let i = interestRate - 0.02; i<= interestRate + 0.02; i += 0.005 ) -//credit score adjustment loop - if (creditScore > 740) { - monthlyInterestRate = monthlyInterestRate * 0.95; + {//for loop beginning + //set variable values + let monthlyInterestRate = i/12; + let periods = years*12; - } else if (creditScore < 600) { - monthlyInterestRate = monthlyInterestRate * 1.05; - - } else if (creditScore >= 600 && creditScore <= 740) { - // No adjustment placeholder only - } - -//formula calculation - let n1 = Math.pow((1 + monthlyInterestRate), periods); - let numerator = (principle * n1 * monthlyInterestRate); - let denominator = (n1 - 1); - let monthlyRate = (numerator / denominator); - -//creates bottom of the variable interest rate progression - let variableInterestRate = interestRate - 0.02; - -//Rounders - roundedVariableInterest = variableInterestRate.toFixed(3); - roundedMonthlyRate = monthlyRate.toFixed(2); - -//data return - return `${name}, with an interest rate of ${roundedVariableInterest}, your monthly rate is ${roundedMonthlyRate}`; + //formula + let n1 = Math.pow(1 + monthlyInterestRate, periods); + let numerator = principal * n1 * monthlyInterestRate; + let denominator = n1 -1; + let monthlyRate = numerator/denominator; -//adds and equalizes interestRate with 0.005 - - interestRate += 0.005; + //output with consolidated rounders. + console.log (`${name}, with an interest rate of ${i.toFixed(3)}, your monthly rate is $${Math.round(monthlyRate)}`); } -// output - var output = mortgageCalculator('Oscar', 200000, 0.05, 30, 530); - console.log(output); - } } -//function call to execute program - -variableInterestRate(); - - - +variableInterestRate ('Tony', 200000, 0.04, 30);