From 262682f9e6647e02fc385cb5b641ee1716dc64ac Mon Sep 17 00:00:00 2001 From: samuel singletary Date: Sat, 17 Oct 2020 20:20:44 -0400 Subject: [PATCH 1/2] Halfway done --- index.js | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 667af155..13856659 100644 --- a/index.js +++ b/index.js @@ -4,8 +4,12 @@ /* 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. */ +var log = console.log; - +var principal = 200000; +var interestRate = 0.05; +var years = 30; +var name = "Cody" // 🏡 Task 1.5: Simple Math @@ -15,7 +19,8 @@ (2) Create another variable called `periods` and give it the value of years*12. */ - +var monthlyInterestRate = interestRate / 12; +var periods = years * 12; // 🏡 Task 2: Harder Math @@ -35,7 +40,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 */ - +var n1 = (1 + monthlyInterestRate)**periods; +var numerator = principal * n1 * monthlyInterestRate; +var denominator = n1 - 1; +var monthlyRate = numerator/denominator +log(monthlyRate) // 🏡 Task 3: Function @@ -44,8 +53,9 @@ 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 () { + log(name+", your monthly rate is $"+monthlyRate) +} // 🏡 Task 4: Arguments and Parameters @@ -55,7 +65,20 @@ For example, mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64 */ +function mortgageCalculator2 (P, I, N) { + + let periods = N * 12; + let interest = I / 12; + let N1 = (1 + interest) ** periods; + let numerator = P * N1 * interest; + let denominator = N1 - 1; + let monthlyRate = numerator/denominator + + + log(name+", your monthly rate is $"+monthlyRate) +} +mortgageCalculator2(200000, 0.05, 30) From e25fa0284bf7c95683e11860e372bb0b8338f7f2 Mon Sep 17 00:00:00 2001 From: samuel singletary Date: Sun, 18 Oct 2020 10:45:30 -0400 Subject: [PATCH 2/2] finished product --- index.js | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 13856659..34c94200 100644 --- a/index.js +++ b/index.js @@ -53,9 +53,6 @@ log(monthlyRate) If your name is `Oscar` mortgageCalculator() should return "Oscar, your monthly rate is 1073.64" */ -function mortgageCalculator () { - log(name+", your monthly rate is $"+monthlyRate) -} // 🏡 Task 4: Arguments and Parameters @@ -65,8 +62,8 @@ For example, mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64 */ -function mortgageCalculator2 (P, I, N) { - +function mortgageCalculator (P, I, N, C) { + let periods = N * 12; let interest = I / 12; let N1 = (1 + interest) ** periods; @@ -74,11 +71,17 @@ function mortgageCalculator2 (P, I, N) { let denominator = N1 - 1; let monthlyRate = numerator/denominator + if (C > 740) { + monthlyRate = monthlyRate * .95 + } + else if ( C < 660) { + monthlyRate = monthlyRate * 1.05 + } log(name+", your monthly rate is $"+monthlyRate) } -mortgageCalculator2(200000, 0.05, 30) + @@ -109,8 +112,36 @@ 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, C) { + + + var i; + for (i=0; i < 10; i++){ + + let periods = N * 12; + let interest = I / 12; + let N1 = (1 + interest) ** periods; + let numerator = P * N1 * interest; + let denominator = N1 - 1; + let monthlyRate = numerator/denominator + + if (C > 740) { + monthlyRate = monthlyRate * .95 + } + else if ( C < 660) { + monthlyRate = monthlyRate * 1.05 + } + + + log(name+", with and interest rate of "+I.toFixed(3)+" your monthly rate is $"+monthlyRate) + I = I + .005 + } + + +} +variableInterestRate(200000, .05, 30) // 🌟🌟🌟 STRETCH 🌟🌟🌟//