From 374a99ab76c20cf8e08413f24433b559283a9ffd Mon Sep 17 00:00:00 2001 From: Molly Brown Date: Sun, 18 Oct 2020 14:42:57 -0400 Subject: [PATCH 1/5] Fixed the wrong wording in the assignment's Task 1 question. Completed creating the variables. --- index.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 667af155..b6266d37 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,12 @@ // 🌟🌟🌟 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. -*/ - - +/* Create variables for principal, interest rate, and years. Assign them the values 200000, 0.05, and 30 respectively. Create another variable called name and give it the value of your own name. +*/ +let principal=200000; +let interestRate=0.05; +let years=30; +let name="Molly"; From 33eace2ffeb3fbc25c394014cbf44da265f022a1 Mon Sep 17 00:00:00 2001 From: Molly Brown Date: Sun, 18 Oct 2020 14:58:10 -0400 Subject: [PATCH 2/5] Completed Task 1.5 --- index.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index b6266d37..54e4e372 100644 --- a/index.js +++ b/index.js @@ -3,10 +3,10 @@ // 🏡 Task 1: Variables /* Create variables for principal, interest rate, and years. Assign them the values 200000, 0.05, and 30 respectively. Create another variable called name and give it the value of your own name. */ -let principal=200000; -let interestRate=0.05; -let years=30; -let name="Molly"; +const principal=200000; +const interestRate=0.05; +const years=30; +const name="Molly"; @@ -16,7 +16,8 @@ let name="Molly"; (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); +let periods= (years * 12); From f9eac1e2b26d9d1035a41f26940b9670ec1943ee Mon Sep 17 00:00:00 2001 From: Molly Brown Date: Sun, 18 Oct 2020 21:24:46 -0400 Subject: [PATCH 3/5] Completed tasks one through 4. I used different, more descriptive variable names than what was specified. --- index.js | 104 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 91 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index 54e4e372..0dfebf5d 100644 --- a/index.js +++ b/index.js @@ -1,12 +1,12 @@ // 🌟🌟🌟 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 variable called name and give it the value of your own name. -*/ -const principal=200000; -const interestRate=0.05; -const years=30; -const name="Molly"; +/* 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; // principal +let annualInterestRate = 0.05; // interestRate +let loanDurationYears = 30; // years +let name = "Molly"; @@ -16,8 +16,10 @@ const name="Molly"; (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); -let periods= (years * 12); + +const monthsInYear = 12; +const monthlyInterestRate = annualInterestRate / monthsInYear; // I +const paymentPeriods = loanDurationYears * monthsInYear; // N @@ -38,6 +40,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 */ +const n1 = Math.pow( (1 + monthlyInterestRate), paymentPeriods); // (1 + monthlyInterestRate )^N +const numerator = principal * n1 * monthlyInterestRate; // p * n1 * monthlyInterestRate +const denominator = n1 - 1; // n1 - 1 +const monthlyRate = numerator / denominator; // monthlyRate = numerator / denominator + +console.log("Step 2, monthlyRate: $", monthlyRate); @@ -46,10 +54,29 @@ 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 taskThreeMortgageCalculator() { + // Step 1 + const principal = 200000; // principal + const annualInterestRate = 0.05; // interestRate + const loanDurationYears = 30; // years + const name = "Molly"; + + // Step 1.5 + const monthsInYear = 12; + const monthlyInterestRate = annualInterestRate / monthsInYear; // I + const paymentPeriods = loanDurationYears * monthsInYear; // N + + // Step 2 + const n1 = Math.pow( (1 + monthlyInterestRate), paymentPeriods); // (1 + monthlyInterestRate )^N + const numerator = principal * n1 * monthlyInterestRate; // p * n1 * monthlyInterestRate + const denominator = n1 - 1; // n1 - 1 + const monthlyRate = numerator / denominator; // monthlyRate = numerator / denominator + + return name + ", your monthly rate is " + monthlyRate; +} + +console.log('~~~~~~~~~~~~~~~~~'); +console.log("Step 3:" + taskThreeMortgageCalculator()); // 🏡 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. @@ -58,6 +85,35 @@ For example, mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64 */ +/** + * Calculates monthly rate of payment for loan. + */ + +function taskFourMortgageCalculator(P, I, N) { + // Step 1 + const principal = P; // principal + const annualInterestRate = I; // interestRate + const loanDurationYears = N; // years + const name = "Molly"; + + // Step 1.5 + const monthsInYear = 12; + const monthlyInterestRate = annualInterestRate / monthsInYear; // I in equation + const paymentPeriods = loanDurationYears * monthsInYear; // N in equation + + // Step 2 + const n1 = Math.pow( (1 + monthlyInterestRate), paymentPeriods); // (1 + monthlyInterestRate )^N + const numerator = principal * n1 * monthlyInterestRate; // p * n1 * monthlyInterestRate + const denominator = n1 - 1; // n1 - 1 + const monthlyRate = numerator / denominator; // monthlyRate = numerator / denominator + + return name + ", your monthly rate is " + monthlyRate; +} +const stepFourResult= taskFourMortgageCalculator(200000, 0.05, 30); +console.log('~~~~~~~~~~~~~~~~~') +console.log("Step 4:" + stepFourResult); + + @@ -69,7 +125,29 @@ 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 taskFiveMortgageCalculator(P, I, N) { + // Step 1 + const principal = P; // principal + const annualInterestRate = I; // interestRate + const loanDurationYears = N; // years + const name = "Molly"; + + // Step 1.5 + const monthsInYear = 12; + const monthlyInterestRate = annualInterestRate / monthsInYear; // I in equation + const paymentPeriods = loanDurationYears * monthsInYear; // N in equation + + // Step 2 + const n1 = Math.pow( (1 + monthlyInterestRate), paymentPeriods); // (1 + monthlyInterestRate )^N + const numerator = principal * n1 * monthlyInterestRate; // p * n1 * monthlyInterestRate + const denominator = n1 - 1; // n1 - 1 + const monthlyRate = numerator / denominator; // monthlyRate = numerator / denominator + + return name + ", your monthly rate is " + monthlyRate; +} +const stepFiveResult= taskFiveMortgageCalculator(200000, 0.05, 30); +console.log('~~~~~~~~~~~~~~~~~') +console.log("Step 5:" + stepFiveResult); From 82831707251f68fe7fb8262cea26cbe3fe13a232 Mon Sep 17 00:00:00 2001 From: Molly Brown Date: Sun, 18 Oct 2020 21:48:31 -0400 Subject: [PATCH 4/5] Completed if/else statement, task 5 --- index.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 0dfebf5d..e6abe632 100644 --- a/index.js +++ b/index.js @@ -43,7 +43,7 @@ When your math is correct, monthlyRate will equal 1073.64 const n1 = Math.pow( (1 + monthlyInterestRate), paymentPeriods); // (1 + monthlyInterestRate )^N const numerator = principal * n1 * monthlyInterestRate; // p * n1 * monthlyInterestRate const denominator = n1 - 1; // n1 - 1 -const monthlyRate = numerator / denominator; // monthlyRate = numerator / denominator +let monthlyRate = numerator / denominator; // monthlyRate = numerator / denominator console.log("Step 2, monthlyRate: $", monthlyRate); @@ -70,7 +70,7 @@ function taskThreeMortgageCalculator() { const n1 = Math.pow( (1 + monthlyInterestRate), paymentPeriods); // (1 + monthlyInterestRate )^N const numerator = principal * n1 * monthlyInterestRate; // p * n1 * monthlyInterestRate const denominator = n1 - 1; // n1 - 1 - const monthlyRate = numerator / denominator; // monthlyRate = numerator / denominator + let monthlyRate = numerator / denominator; // monthlyRate = numerator / denominator return name + ", your monthly rate is " + monthlyRate; } @@ -105,7 +105,7 @@ function taskFourMortgageCalculator(P, I, N) { const n1 = Math.pow( (1 + monthlyInterestRate), paymentPeriods); // (1 + monthlyInterestRate )^N const numerator = principal * n1 * monthlyInterestRate; // p * n1 * monthlyInterestRate const denominator = n1 - 1; // n1 - 1 - const monthlyRate = numerator / denominator; // monthlyRate = numerator / denominator + let monthlyRate = numerator / denominator; // monthlyRate = numerator / denominator return name + ", your monthly rate is " + monthlyRate; } @@ -125,7 +125,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 taskFiveMortgageCalculator(P, I, N) { +function taskFiveMortgageCalculator(P, I, N, creditScore) { // Step 1 const principal = P; // principal const annualInterestRate = I; // interestRate @@ -141,11 +141,19 @@ function taskFiveMortgageCalculator(P, I, N) { const n1 = Math.pow( (1 + monthlyInterestRate), paymentPeriods); // (1 + monthlyInterestRate )^N const numerator = principal * n1 * monthlyInterestRate; // p * n1 * monthlyInterestRate const denominator = n1 - 1; // n1 - 1 - const monthlyRate = numerator / denominator; // monthlyRate = numerator / denominator + let monthlyRate = numerator / denominator; // monthlyRate = numerator / denominator + + if (creditScore > 740){ + monthlyRate = monthlyRate * 0.95; + } else if (creditScore < 660){ + monthlyRate = monthlyRate * 1.05; + } else if (creditScore > 660 && creditScore < 740) { + monthlyRate = monthlyRate; + } return name + ", your monthly rate is " + monthlyRate; } -const stepFiveResult= taskFiveMortgageCalculator(200000, 0.05, 30); +const stepFiveResult= taskFiveMortgageCalculator(200000, 0.05, 30, 800); console.log('~~~~~~~~~~~~~~~~~') console.log("Step 5:" + stepFiveResult); From 0d185c114455b6814ca9e77c66deae0361858db7 Mon Sep 17 00:00:00 2001 From: Molly Brown Date: Sun, 18 Oct 2020 22:15:16 -0400 Subject: [PATCH 5/5] Didn't finish, but turning in completed project to task 5 --- index.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/index.js b/index.js index e6abe632..71af53af 100644 --- a/index.js +++ b/index.js @@ -174,7 +174,33 @@ 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(P, I, N) { + // Step 1 + const principal = P; // principal + const annualInterestRate = I; // interestRate + const loanDurationYears = N; // years + const name = "Molly"; + + // Step 1.5 + const monthsInYear = 12; + const monthlyInterestRate = annualInterestRate / monthsInYear; // I in equation + const paymentPeriods = loanDurationYears * monthsInYear; // N in equation + // Step 2 + const n1 = Math.pow( (1 + monthlyInterestRate), paymentPeriods); // (1 + monthlyInterestRate )^N + const numerator = principal * n1 * monthlyInterestRate; // p * n1 * monthlyInterestRate + const denominator = n1 - 1; // n1 - 1 + let monthlyRate = numerator / denominator; // monthlyRate = numerator / denominator + + + + + return name + ", your monthly rate is " + monthlyRate; +} +const stepSixResult= variableInterestRate(200000, 0.05, 30, 800); +console.log('~~~~~~~~~~~~~~~~~') +console.log("Step 6:" + stepSixResult); +console.log(name + ", with an interest rate of 0.02, your monthly rate is $" );