From f383dab1affc73ceb740b0b4f3c390c42270fb60 Mon Sep 17 00:00:00 2001 From: daniel-vazquez Date: Fri, 16 Oct 2020 22:11:05 -0700 Subject: [PATCH 1/8] added variables in tasks 1 & 1.5 --- index.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/index.js b/index.js index 667af155..be673da5 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,17 @@ /* 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 principal = 20000; +console.log(principal) +var interestRate = 0.05 +console.log(interestRate) + +var years = 30 +console.log(years) + +const name = "Dan" +console.log(name) @@ -15,7 +25,11 @@ (2) Create another variable called `periods` and give it the value of years*12. */ +var monthlyInterestRate= (interestRate / 12) +console.log(monthlyInterestRate) +var periods= (years * 12) +console.log(periods) // 🏡 Task 2: Harder Math @@ -38,6 +52,7 @@ 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}" From 02b8dfc2097c26ac50282e2a82a4af2a3081b7cc Mon Sep 17 00:00:00 2001 From: daniel-vazquez Date: Fri, 16 Oct 2020 22:24:59 -0700 Subject: [PATCH 2/8] started variables for task 2, need to insert .math objects to get correct calculation --- index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/index.js b/index.js index be673da5..5f447e8b 100644 --- a/index.js +++ b/index.js @@ -49,7 +49,17 @@ 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)^N +console.log(n1) +var numerator = (p * n1 * monthlyInterestRate) +console.log(numerator) + +var denominator = (n1 - 1) +console.log(denominator) + +var monthlyRate = (numerator / denominator) +console.log(monthlyRate) From 3d02c935511dcd33683005e72ac3732a3eda9873 Mon Sep 17 00:00:00 2001 From: daniel-vazquez Date: Sat, 17 Oct 2020 01:38:13 -0700 Subject: [PATCH 3/8] completed task 3 and started working on task 4. need to research arguments and parameters --- index.js | 58 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 5f447e8b..d38d1414 100644 --- a/index.js +++ b/index.js @@ -4,20 +4,22 @@ /* 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 principal = 20000; +var principal = 200000; console.log(principal) -var interestRate = 0.05 +var interestRate = 0.05; console.log(interestRate) -var years = 30 +var years = 30; console.log(years) -const name = "Dan" +var name = "Dan" console.log(name) + + // 🏡 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. @@ -32,6 +34,7 @@ var periods= (years * 12) console.log(periods) + // 🏡 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. @@ -49,26 +52,43 @@ 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)^N + + +/* var p = [ interestRate(1 + interestRate)^var] / [ (1 + interestRate)^var -1] +console.log(p) *///--this is how the formula should look + + +var n1 = Math.pow (1 + monthlyInterestRate, periods); console.log(n1) -var numerator = (p * n1 * monthlyInterestRate) +var numerator = principal * n1 * monthlyInterestRate; console.log(numerator) -var denominator = (n1 - 1) +var denominator = n1 - 1; console.log(denominator) -var monthlyRate = (numerator / denominator) +var monthlyRate = numerator/denominator; console.log(monthlyRate) + + + + + // 🏡 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 mortgageCalculator() +{ console.log(name,"your monthly rate is",monthlyRate); + +} + +mortgageCalculator(); @@ -80,7 +100,29 @@ For example, mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64 */ +var n1 = Math.pow (1 + monthlyInterestRate, 300); + + +var numerator = principal * n1 * monthlyInterestRate; + +var denominator = n1 - 1; + +var monthlyRate = numerator/denominator; + + +var principal = 150000; +console.log(principal) + +var interestRate = 0.10; +console.log(interestRate) + +var years = 25; + +var name = "Bob"; +console.log(name) + +mortgageCalculator(); From 2e4c5eb035a8bb9e6cb922da089de89f7d19beb7 Mon Sep 17 00:00:00 2001 From: daniel-vazquez Date: Sat, 17 Oct 2020 02:29:45 -0700 Subject: [PATCH 4/8] completed task 4 and created function with variables/arguments --- index.js | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index d38d1414..47e4ffba 100644 --- a/index.js +++ b/index.js @@ -99,30 +99,27 @@ mortgageCalculator(); For example, mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64 */ +function myCalculator(principal, interestRate, years){ -var n1 = Math.pow (1 + monthlyInterestRate, 300); +var periods = years * 12 +var n1 = Math.pow (1 + monthlyInterestRate, periods) -var numerator = principal * n1 * monthlyInterestRate; +var numerator = principal * n1 * monthlyInterestRate -var denominator = n1 - 1; +var denominator = n1 - 1 -var monthlyRate = numerator/denominator; +var monthlyRate = numerator/denominator +console.log(monthlyRate) -var principal = 150000; -console.log(principal) -var interestRate = 0.10; -console.log(interestRate) +} -var years = 25; -var name = "Bob"; -console.log(name) -mortgageCalculator(); +myCalculator(150000, 0.1, 5); From cebcfecc19987bec22c175d5646697de1e7a0696 Mon Sep 17 00:00:00 2001 From: daniel-vazquez Date: Sun, 18 Oct 2020 11:32:44 -0700 Subject: [PATCH 5/8] started task 5, need to fix function so that monthly rate increases/decreases based on credit score --- index.js | 51 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 47e4ffba..7389c0e7 100644 --- a/index.js +++ b/index.js @@ -16,6 +16,8 @@ console.log(years) var name = "Dan" console.log(name) +var creditScore = 800; + @@ -27,10 +29,10 @@ console.log(name) (2) Create another variable called `periods` and give it the value of years*12. */ -var monthlyInterestRate= (interestRate / 12) +var monthlyInterestRate= interestRate / 12 console.log(monthlyInterestRate) -var periods= (years * 12) +var periods= years * 12 console.log(periods) @@ -54,9 +56,6 @@ When your math is correct, monthlyRate will equal 1073.64 -/* var p = [ interestRate(1 + interestRate)^var] / [ (1 + interestRate)^var -1] -console.log(p) *///--this is how the formula should look - var n1 = Math.pow (1 + monthlyInterestRate, periods); console.log(n1) @@ -84,7 +83,7 @@ If your name is `Oscar` mortgageCalculator() should return "Oscar, your monthly */ function mortgageCalculator() -{ console.log(name,"your monthly rate is",monthlyRate); +{ console.log(name,"your monthly rate is $",monthlyRate.toFixed(2)); } @@ -111,18 +110,17 @@ var denominator = n1 - 1 var monthlyRate = numerator/denominator -console.log(monthlyRate) +console.log("$",monthlyRate.toFixed(2)) } - - myCalculator(150000, 0.1, 5); + // 🏡 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). @@ -132,6 +130,41 @@ Hint: To drop an interest rate by 5% you can take monthlyRate and multiply it by */ +function myCalculator(principal, interestRate, years, creditScore){ + + var periods = years * 12 + + var n1 = Math.pow (1 + monthlyInterestRate, periods) + + var numerator = principal * n1 * monthlyInterestRate + + var denominator = n1 - 1 + + var monthlyRate = numerator/denominator + + if (creditScore > 740) { + monthlyRate * 0.95; + console.log('perfect credit'); + } + + + else if (creditScore < 660) { + monthlyRate * 1.05; + console.log('bad credit'); + } + + else { + console.log('average credit') + } + + console.log("$",monthlyRate.toFixed(2)) + + + } + + +myCalculator(150000, 0.05, 20, 741); + // 🏡 Task 6: Loops From 114b187ff774d5a76cf4ad5449c1097ad30e8c12 Mon Sep 17 00:00:00 2001 From: daniel-vazquez Date: Sun, 18 Oct 2020 11:42:49 -0700 Subject: [PATCH 6/8] completed task 5 and working on 6, added notes for 'for loop' --- index.js | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 7389c0e7..20e408d5 100644 --- a/index.js +++ b/index.js @@ -143,13 +143,13 @@ function myCalculator(principal, interestRate, years, creditScore){ var monthlyRate = numerator/denominator if (creditScore > 740) { - monthlyRate * 0.95; + monthlyRate *= 0.95; console.log('perfect credit'); } else if (creditScore < 660) { - monthlyRate * 1.05; + monthlyRate *= 1.05; console.log('bad credit'); } @@ -163,7 +163,7 @@ function myCalculator(principal, interestRate, years, creditScore){ } -myCalculator(150000, 0.05, 20, 741); +myCalculator(150000, 0.05, 20, 740); @@ -184,6 +184,45 @@ For example, variableInterestRate(200000, 0.04, 30) should console.log: */ +/* <---Reference the code below---> +for (let i= 0; i < 5; i++) { + console.log('hello world' + +}*/ + +variableInterestRate () { + + var periods = years * 12 + + var n1 = Math.pow (1 + monthlyInterestRate, periods) + + var numerator = principal * n1 * monthlyInterestRate + + var denominator = n1 - 1 + + var monthlyRate = numerator/denominator + + if (creditScore > 740) { + monthlyRate *= 0.95; + console.log('perfect credit'); +} + + + else if (creditScore < 660) { + monthlyRate *= 1.05; + console.log('bad credit'); +} + + else { + console.log('average credit') +} + + +console.log("$",monthlyRate.toFixed(2)) + + +} + // 🌟🌟🌟 STRETCH 🌟🌟🌟// From 98a3a53eee9d534fc2e85325ef7917aa7e59a510 Mon Sep 17 00:00:00 2001 From: daniel-vazquez Date: Sun, 18 Oct 2020 12:05:08 -0700 Subject: [PATCH 7/8] created function variableInterestRate and writing loop as requried per task 6 --- index.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 20e408d5..e854abf7 100644 --- a/index.js +++ b/index.js @@ -157,13 +157,12 @@ function myCalculator(principal, interestRate, years, creditScore){ console.log('average credit') } - console.log("$",monthlyRate.toFixed(2)) + console.log(name,"your monthly rate is $",monthlyRate.toFixed(2)) - } - +} -myCalculator(150000, 0.05, 20, 740); +myCalculator(150000, 0.05, 20, 800); @@ -184,13 +183,16 @@ For example, variableInterestRate(200000, 0.04, 30) should console.log: */ + + + /* <---Reference the code below---> for (let i= 0; i < 5; i++) { console.log('hello world' }*/ -variableInterestRate () { +function variableInterestRate() { var periods = years * 12 From 452641cb96ffefb10cc82a946ff20e9462b792dc Mon Sep 17 00:00:00 2001 From: daniel-vazquez Date: Sun, 18 Oct 2020 14:49:55 -0700 Subject: [PATCH 8/8] completed task 6 and added loop for variableInterest function, was unable to get 10 outputs but didn't want to break code --- index.js | 99 +++++++++++++++++++++++++++----------------------------- 1 file changed, 47 insertions(+), 52 deletions(-) diff --git a/index.js b/index.js index e854abf7..a202bf0b 100644 --- a/index.js +++ b/index.js @@ -4,17 +4,14 @@ /* 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 principal = 200000; -console.log(principal) var interestRate = 0.05; -console.log(interestRate) var years = 30; -console.log(years) var name = "Dan" -console.log(name) var creditScore = 800; @@ -30,10 +27,10 @@ var creditScore = 800; */ var monthlyInterestRate= interestRate / 12 -console.log(monthlyInterestRate) + var periods= years * 12 -console.log(periods) + @@ -58,13 +55,13 @@ When your math is correct, monthlyRate will equal 1073.64 var n1 = Math.pow (1 + monthlyInterestRate, periods); -console.log(n1) + var numerator = principal * n1 * monthlyInterestRate; -console.log(numerator) + var denominator = n1 - 1; -console.log(denominator) + var monthlyRate = numerator/denominator; console.log(monthlyRate) @@ -98,25 +95,23 @@ mortgageCalculator(); For example, mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64 */ -function myCalculator(principal, interestRate, years){ - -var periods = years * 12 - -var n1 = Math.pow (1 + monthlyInterestRate, periods) - -var numerator = principal * n1 * monthlyInterestRate +function myCalculator(p, i, n){ -var denominator = n1 - 1 - -var monthlyRate = numerator/denominator + var n1 = Math.pow((1 + (i/12)), (n*12)); + + var numerator = p * n1 * (i/12); + + var denominator = n1 - 1; + + var monthlyRate = numerator / denominator ; -console.log("$",monthlyRate.toFixed(2)) + return console.log("$",monthlyRate.toFixed(2)) } -myCalculator(150000, 0.1, 5); +myCalculator(150000, 0.1, 15); @@ -130,39 +125,37 @@ Hint: To drop an interest rate by 5% you can take monthlyRate and multiply it by */ -function myCalculator(principal, interestRate, years, creditScore){ +function myCalculatorTwo(p, i, n, creditScore){ - var periods = years * 12 + var n1 = Math.pow((1 + (i/12)), (n*12)); - var n1 = Math.pow (1 + monthlyInterestRate, periods) + var numerator = p * n1 * (i/12); - var numerator = principal * n1 * monthlyInterestRate + var denominator = n1 - 1; - var denominator = n1 - 1 - - var monthlyRate = numerator/denominator + var monthlyRate = numerator / denominator ; if (creditScore > 740) { monthlyRate *= 0.95; - console.log('perfect credit'); + } else if (creditScore < 660) { monthlyRate *= 1.05; - console.log('bad credit'); + } else { console.log('average credit') } - console.log(name,"your monthly rate is $",monthlyRate.toFixed(2)) + return console.log(name,"your monthly rate is $",monthlyRate.toFixed(2)) } -myCalculator(150000, 0.05, 20, 800); +myCalculatorTwo(150000, 0.05, 20, 500); @@ -187,43 +180,40 @@ For example, variableInterestRate(200000, 0.04, 30) should console.log: /* <---Reference the code below---> + for (let i= 0; i < 5; i++) { - console.log('hello world' + console.log('hello world') +} }*/ -function variableInterestRate() { +function variableInterestRate(p, i, n) { + - var periods = years * 12 + let n1 = Math.pow((1 + (i/12)), (n*12)) - var n1 = Math.pow (1 + monthlyInterestRate, periods) + let numerator = p * n1 * (i/12); + + let denominator = n1 - 1; + + let monthlyRate = numerator / denominator ; - var numerator = principal * n1 * monthlyInterestRate + return monthlyRate; - var denominator = n1 - 1 +} - var monthlyRate = numerator/denominator + for (let d= .02; d <.06; d+=0.005){ - if (creditScore > 740) { - monthlyRate *= 0.95; - console.log('perfect credit'); -} + console.log(name,"with an interest rate of",d.toFixed(3),"your monthly variable rate is $", variableInterestRate(200000,d.toFixed(2),30)); - else if (creditScore < 660) { - monthlyRate *= 1.05; - console.log('bad credit'); -} + } - else { - console.log('average credit') -} +variableInterestRate(200000, 0.04, 30); -console.log("$",monthlyRate.toFixed(2)) -} @@ -241,3 +231,8 @@ console.log("$",monthlyRate.toFixed(2)) /* 🏡 Refactor your `variableInterestRate()` function to accept an array of interest rates (make sure to copy and paste as to not lose your work!) */ + + + + +