From 9fd6737a1566621cb967bd38aeefd9f057eb6c1e Mon Sep 17 00:00:00 2001 From: Itismenat <65092546+Itismenat@users.noreply.github.com> Date: Sat, 17 Oct 2020 16:10:17 -0500 Subject: [PATCH 1/6] first task done --- index.js | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/index.js b/index.js index 667af155..356b3a57 100644 --- a/index.js +++ b/index.js @@ -2,11 +2,12 @@ // 🏡 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 = 0.05; +let years = 30; +const name = "Natalia Golebiewski"; // 🏡 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. @@ -15,8 +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 /* 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. @@ -35,19 +36,12 @@ 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 */ - - - // 🏡 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" */ - - - - // 🏡 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,10 +49,6 @@ For example, mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64 */ - - - - // 🏡 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). @@ -67,9 +57,6 @@ 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. */ - - - // 🏡 Task 6: Loops /* Write a new function called variableInterestRate. This function should be the same as mortgageCalculator, except it should console.log the monthly payment for 10 different interest rates at 0.5% increments plus or minus 2% from the inputted interest rate. Complete these calculations using a for loop. @@ -86,20 +73,14 @@ For example, variableInterestRate(200000, 0.04, 30) should console.log: "{Name}, with an interest rate of 0.06, your monthly rate is $1199" */ - - - // 🌟🌟🌟 STRETCH 🌟🌟🌟// /* Attempt any of the stretch goals below once you have finished the work above. Remember as always, these may require additional research beyond what you learned today */ /* 🏡 Add `Property Tax`, `Homeowner's insurance` and `HOA fees` as parameters in your function to calculate total monthly spending on housing */ - /* 🏡 Build a calculator function that accepts `monthly payment` and `interest rate` and returns the maximum loan that a person could afford */ - /* 🏡 Explore using `window.prompt()` to allow a user to input parameters in the browser */ - /* 🏡 Refactor your `variableInterestRate()` function to accept an array of interest rates (make sure to copy and paste as to not lose your work!) */ From 443923c28da87fa3c20b7f006b84d8a4295c3780 Mon Sep 17 00:00:00 2001 From: Itismenat <65092546+Itismenat@users.noreply.github.com> Date: Sat, 17 Oct 2020 17:44:47 -0500 Subject: [PATCH 2/6] second task done --- index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/index.js b/index.js index 356b3a57..42e37581 100644 --- a/index.js +++ b/index.js @@ -36,6 +36,13 @@ 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; +const n2 = Math.pow(n1, periods); +const n3 = monthlyInterestRate * n2; +const n4 = principal * n3; +const n5 = n2 - 1; +let monthlyRate = n4 / n5; + // 🏡 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}" From f10d3ba8c2a0e968d13f04771ff343b0e314e98f Mon Sep 17 00:00:00 2001 From: Itismenat <65092546+Itismenat@users.noreply.github.com> Date: Sat, 17 Oct 2020 18:15:03 -0500 Subject: [PATCH 3/6] third task done --- index.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/index.js b/index.js index 42e37581..e7a66617 100644 --- a/index.js +++ b/index.js @@ -49,6 +49,24 @@ let monthlyRate = n4 / n5; If your name is `Oscar` mortgageCalculator() should return "Oscar, your monthly rate is 1073.64" */ +function mortgageCalculator() { + let principal = 200000; + let interestRate = 0.05; + let years = 30; + const name = "Natalia Golebiewski"; + let monthlyInterestRate = interestRate / 12; + let periods = years * 12; + const n1 = 1 + monthlyInterestRate; + const n2 = Math.pow(n1, periods); + const n3 = monthlyInterestRate * n2; + const n4 = principal * n3; + const n5 = n2 - 1; + let monthlyRate = n4 / n5; + 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. From 3d00010528f761b8d32fd49edb930845dffd9b0f Mon Sep 17 00:00:00 2001 From: Itismenat <65092546+Itismenat@users.noreply.github.com> Date: Sat, 17 Oct 2020 18:31:52 -0500 Subject: [PATCH 4/6] fourth task done --- index.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/index.js b/index.js index e7a66617..2d60ba04 100644 --- a/index.js +++ b/index.js @@ -74,6 +74,19 @@ For example, mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64 */ +function calculations(principal, interestRate, years) { + const name = "Natalia Golebiewski"; + let monthlyInterestRate = interestRate / 12; + let periods = years * 12; + const n1 = 1 + monthlyInterestRate; + const n2 = Math.pow(n1, periods); + const n3 = monthlyInterestRate * n2; + const n4 = principal * n3; + const n5 = n2 - 1; + let monthlyRate = n4 / n5; +} + +calculations(200000, 0.05, 30); // 🏡 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). From 188a8de41df76bd0b40c14ca6e44c4b52ad63c92 Mon Sep 17 00:00:00 2001 From: Itismenat <65092546+Itismenat@users.noreply.github.com> Date: Sat, 17 Oct 2020 22:32:55 -0500 Subject: [PATCH 5/6] fifth task done --- good-version.js | 95 +++++++++++++++++++++++++++++++++++++++++++++++++ index.js | 29 ++++++++++++++- 2 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 good-version.js diff --git a/good-version.js b/good-version.js new file mode 100644 index 00000000..a9adf245 --- /dev/null +++ b/good-version.js @@ -0,0 +1,95 @@ +// :star2::star2::star2: M V P :star2::star2::star2:// +// :house_with_garden: 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. + */ +const principal = 200000; +const interestRate = 0.05; +const years = 30; +const name = "Natalia Golebiewski"; +// :house_with_garden: 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. +*/ +const monthlyInterestRate = interestRate / 12; +const periods = years * 12; +// :house_with_garden: 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. +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 +(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! +When your math is correct, monthlyRate will equal 1073.64 +*/ +const n1 = Math.pow(1 + monthlyInterestRate, periods); +const numerator = principal * n1 * monthlyInterestRate; +const denominator = n1 - 1; +const monthlyRate = Number(numerator / denominator).toFixed(2); +// :house_with_garden: 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 mortgageCalculator1() { + return name + ", your monthly rate is " + monthlyRate; +} +const result1 = mortgageCalculator1(); +console.log("Task 3:", result1); +// :house_with_garden: 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. +For example, +mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64 +*/ +function mortgageCalculator2(principal, interestRate, years) { + const monthlyInterestRate = interestRate / 12; + const periods = years * 12; + const n1 = Math.pow(1 + monthlyInterestRate, periods); + const numerator = principal * n1 * monthlyInterestRate; + const denominator = n1 - 1; + const monthlyRate = numerator / denominator; + return Number(monthlyRate).toFixed(2); +} +const result2 = mortgageCalculator2(200000, 0.05, 30); +console.log("Task 4:", result2); +// :house_with_garden: Task 5: Conditionals +/* Add another parameter 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 0.5% you can take monthlyRate and multiply it by 0.95. Similarly, to increase an interest rate by 0.5% you'd do monthlyRate * 1.05. +*/ +function mortgageCalculator3(principal, interestRate, years, creditScore) { + if (creditScore > 740) { + interestRate = interestRate * 0.95; + } else if (creditScore < 660) { + interestRate = interestRate * 1.05; + } + const monthlyInterestRate = interestRate / 12; + const periods = years * 12; + const n1 = Math.pow(1 + monthlyInterestRate, periods); + const numerator = principal * n1 * monthlyInterestRate; + const denominator = n1 - 1; + const monthlyRate = numerator / denominator; + return Number(monthlyRate).toFixed(2); +} +const result3 = mortgageCalculator3(200000, 0.05, 30, 500); +console.log("Task 5:", result3); +// :house_with_garden: Task 6: Loops +/* Write a new function called variableInterestRate. This function should be the same as mortgageCalculator, except it should console.log the monthly payment for 10 different interest rates at 0.5% increments plus or minus 2% from the inputted interest rate. Complete these calculations using a for loop. +For example, variableInterestRate(200000, 0.04, 30) should console.log: +"{Name}, with an interest rate of 0.02, your monthly rate is $739" +"{Name}, with an interest rate of 0.025, your monthly rate is $790" +"{Name}, with an interest rate of 0.03, your monthly rate is $843" +"{Name}, with an interest rate of 0.035, your monthly rate is $898" +"{Name}, with an interest rate of 0.04, your monthly rate is $955" +"{Name}, with an interest rate of 0.045, your monthly rate is $1013" +"{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" +*/ +// :star2::star2::star2: STRETCH :star2::star2::star2:// +/* Attempt any of the stretch goals below once you have finished the work above. Remember as always, these may require additional research beyond what you learned today */ +/* :house_with_garden: Add `Property Tax`, `Homeowner's insurance` and `HOA fees` as parameters in your function to calculate total monthly spending on housing */ +/* :house_with_garden: Build a calculator function that accepts `monthly payment` and `interest rate` and returns the maximum loan that a person could afford */ +/* :house_with_garden: Explore using `window.prompt()` to allow a user to input parameters in the browser */ +/* :house_with_garden: Refactor your `variableInterestRate()` function to accept an array of interest rates (make sure to copy and paste as to not lose your work!) */ diff --git a/index.js b/index.js index 2d60ba04..754eb0a6 100644 --- a/index.js +++ b/index.js @@ -84,9 +84,11 @@ function calculations(principal, interestRate, years) { const n4 = principal * n3; const n5 = n2 - 1; let monthlyRate = n4 / n5; + return monthlyRate; } +const result4 = calculations(200000, 0.05, 30); +console.log(result4); -calculations(200000, 0.05, 30); // 🏡 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). @@ -95,6 +97,31 @@ 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 calculatorWithCreditScore( + principal, + interestRate, + years, + creditScore +) { + if (creditScore > 740) { + interestRate = interestRate * 0.95; + } else if (creditScore < 660) { + interestRate = interestRate * 1.05; + } + const name = "Natalia Golebiewski"; + let monthlyInterestRate = interestRate / 12; + let periods = years * 12; + const n1 = 1 + monthlyInterestRate; + const n2 = Math.pow(n1, periods); + const n3 = monthlyInterestRate * n2; + const n4 = principal * n3; + const n5 = n2 - 1; + let monthlyRate = n4 / n5; + return monthlyRate; +} +const task5 = calculatorWithCreditScore(200000, 0.05, 30, 770); +console.log(task5); + // 🏡 Task 6: Loops /* Write a new function called variableInterestRate. This function should be the same as mortgageCalculator, except it should console.log the monthly payment for 10 different interest rates at 0.5% increments plus or minus 2% from the inputted interest rate. Complete these calculations using a for loop. From 0bf0b648a84e111307c59613371020576eb9fa7b Mon Sep 17 00:00:00 2001 From: Itismenat <65092546+Itismenat@users.noreply.github.com> Date: Sun, 18 Oct 2020 19:16:47 -0500 Subject: [PATCH 6/6] fifth task done --- index.js | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 754eb0a6..ded6d0c6 100644 --- a/index.js +++ b/index.js @@ -138,14 +138,33 @@ For example, variableInterestRate(200000, 0.04, 30) should console.log: "{Name}, with an interest rate of 0.06, your monthly rate is $1199" */ -// 🌟🌟🌟 STRETCH 🌟🌟🌟// - -/* Attempt any of the stretch goals below once you have finished the work above. Remember as always, these may require additional research beyond what you learned today */ - -/* 🏡 Add `Property Tax`, `Homeowner's insurance` and `HOA fees` as parameters in your function to calculate total monthly spending on housing */ - -/* 🏡 Build a calculator function that accepts `monthly payment` and `interest rate` and returns the maximum loan that a person could afford */ - -/* 🏡 Explore using `window.prompt()` to allow a user to input parameters in the browser */ +function variableInterestRate(principal, interestRate, years, creditScore) { + const name = "Natalia Golebiewski"; + let monthlyInterestRate = interestRate / 12; + let periods = years * 12; + const n1 = 1 + monthlyInterestRate; + const n2 = Math.pow(n1, periods); + const n3 = monthlyInterestRate * n2; + const n4 = principal * n3; + const n5 = n2 - 1; + let monthlyRate = n4 / n5; -/* 🏡 Refactor your `variableInterestRate()` function to accept an array of interest rates (make sure to copy and paste as to not lose your work!) */ + for (i = 0; i < 10; i++) { + if (creditScore > 740) { + monthlyRate = monthlyRate * 0.95; + } else if (creditScore < 660) { + monthlyRate = monthlyRate * 1.05; + } + + console.log( + name, + ", with an interest rate of", + interestRate.toFixed(4), + "your monthly rate is", + monthlyRate.toFixed(2) + ); + interestRate = interestRate + 0.005; + } + return monthlyRate; +} +variableInterestRate(200000, 0.05, 30, 760);