From 18f99cb241a0cbc0debc748273cfacb11714ce37 Mon Sep 17 00:00:00 2001 From: AviasNelan Date: Sun, 18 Oct 2020 08:46:04 -0500 Subject: [PATCH 1/5] first pass --- index.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 667af155..a2cf2031 100644 --- a/index.js +++ b/index.js @@ -3,7 +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 value called name and give it the value of your own name. */ - +let principal = 200000; +let interestRate = 0.05; +let years = 30; +const name = 'Brandon'; @@ -14,7 +17,8 @@ (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); @@ -34,7 +38,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 */ - +let n1 = Math.pow((1 + monthlyInterestRate) , periods); +let numerator = (p * n1 * monthlyInterestRate); +let denominator = (n1 -1); +let monthlyRate = (numerator / denominator); +return monthlyRate; +console.log (monthlyRate); From e207e18d315790aba880b39519202f6fc3bcd46a Mon Sep 17 00:00:00 2001 From: AviasNelan Date: Sun, 18 Oct 2020 09:52:07 -0500 Subject: [PATCH 2/5] steps 1-3 complete --- index.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index a2cf2031..33d5691f 100644 --- a/index.js +++ b/index.js @@ -39,11 +39,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 */ let n1 = Math.pow((1 + monthlyInterestRate) , periods); -let numerator = (p * n1 * monthlyInterestRate); +let numerator = (principal * n1 * monthlyInterestRate); let denominator = (n1 -1); let monthlyRate = (numerator / denominator); -return monthlyRate; console.log (monthlyRate); + P = principal; + I = interestRate; + N = periods; @@ -52,6 +54,11 @@ console.log (monthlyRate); If your name is `Oscar` mortgageCalculator() should return "Oscar, your monthly rate is 1073.64" */ +function mortgageCalculator(P, I, N) +{ + console.log (name + ', your monthly rate is $' + (monthlyRate).toFixed(2)); +} +mortgageCalculator(); @@ -64,6 +71,7 @@ For example, mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64 */ +mortgageCalculator (400, 2 , 4); From c55fdce9e0f93d9e0dfe340a0b85b07a4ddb1a57 Mon Sep 17 00:00:00 2001 From: AviasNelan Date: Sun, 18 Oct 2020 10:47:02 -0500 Subject: [PATCH 3/5] tasks 4 and 5 complete --- index.js | 74 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 54 insertions(+), 20 deletions(-) diff --git a/index.js b/index.js index 33d5691f..a14b4ca8 100644 --- a/index.js +++ b/index.js @@ -3,9 +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 value called name and give it the value of your own name. */ -let principal = 200000; -let interestRate = 0.05; -let years = 30; +let P = 200000; +let I = 0.05; +let N = 30; +let CS = 720; const name = 'Brandon'; @@ -17,8 +18,8 @@ const name = 'Brandon'; (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); +// let monthlyInterestRate = (I / 12); +// let periods = (N * 12); @@ -38,15 +39,10 @@ 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 = (principal * n1 * monthlyInterestRate); -let denominator = (n1 -1); -let monthlyRate = (numerator / denominator); -console.log (monthlyRate); - P = principal; - I = interestRate; - N = periods; - +// let n1 = Math.pow((1 + monthlyInterestRate) , periods); +// let numerator = (P * n1 * monthlyInterestRate); +// let denominator = (n1 -1); +// let monthlyRate = (numerator / denominator); // 🏡 Task 3: Function @@ -54,11 +50,28 @@ console.log (monthlyRate); If your name is `Oscar` mortgageCalculator() should return "Oscar, your monthly rate is 1073.64" */ -function mortgageCalculator(P, I, N) -{ +function mortgageCalculator(P, I, N, CS) +{ + if (CS > 740) { + I = (I * 0.95); + } + else if (CS < 660) { + I = (I * 1.05); + } + else { + I = I; + } + let monthlyInterestRate = (I / 12); + let periods = (N * 12); + let n1 = Math.pow((1 + monthlyInterestRate) , periods); + let numerator = (P * n1 * monthlyInterestRate); + let denominator = (n1 -1); + let monthlyRate = (numerator / denominator); + + console.log (name + ', your monthly rate is $' + (monthlyRate).toFixed(2)); } -mortgageCalculator(); +mortgageCalculator(200000, 0.05, 30, 700); @@ -71,7 +84,7 @@ For example, mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64 */ -mortgageCalculator (400, 2 , 4); +mortgageCalculator(200000, 0.05, 30, 650); @@ -84,7 +97,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. */ - +// COMPLETE // 🏡 Task 6: Loops @@ -102,7 +115,28 @@ 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,) { + + if (CS > 740) { + I = (I * 0.95); + } + else if (CS < 660) { + I = (I * 1.05); + } + else { + I = I; + } + let monthlyInterestRate = (I / 12); + let periods = (N * 12); + let n1 = Math.pow((1 + monthlyInterestRate) , periods); + let numerator = (P * n1 * monthlyInterestRate); + let denominator = (n1 -1); + let monthlyRate = (numerator / denominator); + + console.log(name + ", with an interest rate of " + I + ", your monthly rate is " + monthlyRate.toFixed(2)); + +} +variableInterestRate(200000, 0.05, 30); From 6ba39da809ac757a7b2566a07a3380d5233bde53 Mon Sep 17 00:00:00 2001 From: AviasNelan Date: Sun, 18 Oct 2020 13:07:20 -0500 Subject: [PATCH 4/5] task 6 complete --- index.js | 87 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 48 insertions(+), 39 deletions(-) diff --git a/index.js b/index.js index a14b4ca8..042bc380 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 value called name and give it the value of your own name. */ -let P = 200000; -let I = 0.05; -let N = 30; -let CS = 720; +let principal = 200000; +let interestRate = 0.05; +let years = 30; +let creditScore = 720; const name = 'Brandon'; @@ -50,28 +50,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 mortgageCalculator(P, I, N, CS) +function mortgageCalculator(principal, interestRate, years, creditScore) { - if (CS > 740) { - I = (I * 0.95); + let monthlyInterestRate = (interestRate / 12); + let periods = (years * 12); + let n1 = Math.pow((1 + monthlyInterestRate) , periods); + let numerator = (principal * n1 * monthlyInterestRate); + let denominator = (n1 - 1); + let monthlyRate = (numerator / denominator); + if (creditScore > 740) { + interestRate = (interestRate * 0.95); } - else if (CS < 660) { - I = (I * 1.05); + else if (creditScore < 660) { + interestRate = (interestRate * 1.05); } else { - I = I; + interestRate = interestRate; } - let monthlyInterestRate = (I / 12); - let periods = (N * 12); - let n1 = Math.pow((1 + monthlyInterestRate) , periods); - let numerator = (P * n1 * monthlyInterestRate); - let denominator = (n1 -1); - let monthlyRate = (numerator / denominator); - + - console.log (name + ', your monthly rate is $' + (monthlyRate).toFixed(2)); + // console.log (name + ', your monthly rate is $' + (monthlyRate).toFixed(2)); + return monthlyRate; } -mortgageCalculator(200000, 0.05, 30, 700); +// mortgageCalculator(200000, 0.05, 30, 700); @@ -84,7 +85,7 @@ For example, mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64 */ -mortgageCalculator(200000, 0.05, 30, 650); +// mortgageCalculator(200000, 0.05, 30, 650); @@ -115,28 +116,36 @@ 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,) { - - if (CS > 740) { - I = (I * 0.95); - } - else if (CS < 660) { - I = (I * 1.05); - } - else { - I = I; - } - let monthlyInterestRate = (I / 12); - let periods = (N * 12); - let n1 = Math.pow((1 + monthlyInterestRate) , periods); - let numerator = (P * n1 * monthlyInterestRate); - let denominator = (n1 -1); - let monthlyRate = (numerator / denominator); + +function variableInterestRate(principal, interestRate, years, creditScore) { + // let monthlyInterestRate = (interestRate / 12); + // let periods = (years * 12); + // let n1 = Math.pow((1 + monthlyInterestRate) , periods); + // let numerator = (principal * n1 * monthlyInterestRate); + // let denominator = (n1 - 1); + // let monthlyRate = (numerator / denominator); + + // if (creditScore > 740) { + // interestRate = (interestRate * 0.95); + // } + // else if (creditScore < 660) { + // interestRate = (interestRate * 1.05); + // } + // else { + // interestRate = interestRate; + // } + + let variableInterest= interestRate - .02; + for (i= 1; i < 10; i++){ + let monthlyRate = mortgageCalculator(principal, variableInterest, years, creditScore); + console.log (name + ', at an interest rate of ' + variableInterest.toFixed(3) + ", your monthly rate is $" + monthlyRate.toFixed(0)); + variableInterest += 0.005; - console.log(name + ", with an interest rate of " + I + ", your monthly rate is " + monthlyRate.toFixed(2)); + } } -variableInterestRate(200000, 0.05, 30); + +variableInterestRate(200000, 0.04, 30); From aa78c2b86a9c1a2e207d98f660259ca2b2644a61 Mon Sep 17 00:00:00 2001 From: AviasNelan Date: Sun, 18 Oct 2020 13:16:17 -0500 Subject: [PATCH 5/5] MVP --- index.js | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/index.js b/index.js index 042bc380..7ee6dfcf 100644 --- a/index.js +++ b/index.js @@ -68,11 +68,11 @@ function mortgageCalculator(principal, interestRate, years, creditScore) interestRate = interestRate; } - - // console.log (name + ', your monthly rate is $' + (monthlyRate).toFixed(2)); +// console.log (name + ', your monthly rate is $' + (monthlyRate).toFixed(2)); + return monthlyRate; } -// mortgageCalculator(200000, 0.05, 30, 700); +mortgageCalculator(200000, 0.05, 30, 700); @@ -85,7 +85,7 @@ For example, mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64 */ -// mortgageCalculator(200000, 0.05, 30, 650); +mortgageCalculator(200000, 0.05, 30, 650); @@ -118,34 +118,24 @@ For example, variableInterestRate(200000, 0.04, 30) should console.log: */ function variableInterestRate(principal, interestRate, years, creditScore) { - // let monthlyInterestRate = (interestRate / 12); - // let periods = (years * 12); - // let n1 = Math.pow((1 + monthlyInterestRate) , periods); - // let numerator = (principal * n1 * monthlyInterestRate); - // let denominator = (n1 - 1); - // let monthlyRate = (numerator / denominator); - - // if (creditScore > 740) { - // interestRate = (interestRate * 0.95); - // } - // else if (creditScore < 660) { - // interestRate = (interestRate * 1.05); - // } - // else { - // interestRate = interestRate; - // } - + if (creditScore > 740) { + interestRate = (interestRate * 0.95); + } + else if (creditScore < 660) { + interestRate = (interestRate * 1.05); + } + else { + interestRate = interestRate; + } let variableInterest= interestRate - .02; for (i= 1; i < 10; i++){ let monthlyRate = mortgageCalculator(principal, variableInterest, years, creditScore); console.log (name + ', at an interest rate of ' + variableInterest.toFixed(3) + ", your monthly rate is $" + monthlyRate.toFixed(0)); - variableInterest += 0.005; - - + variableInterest += 0.005; } } -variableInterestRate(200000, 0.04, 30); +variableInterestRate(200000, 0.04, 30, 700);