From df56f32a7bdd0cc1d92c6665223f2d41341d5c4b Mon Sep 17 00:00:00 2001 From: josh jacques Date: Sat, 17 Oct 2020 10:56:29 -0500 Subject: [PATCH 1/4] finished task 4 --- index.js | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 667af155..da058e6c 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,10 @@ /* 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 name = "josh" @@ -15,6 +19,12 @@ (2) Create another variable called `periods` and give it the value of years*12. */ +let monthlyInterestRate = interestRate / 12 +let periods = years * 12 + +// console.log (monthlyInterestRate) +// console.log (periods) + @@ -35,8 +45,15 @@ 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(n1); +console.log(numerator); +console.log(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}" @@ -44,9 +61,21 @@ 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(){ + // let principal = 200000 + // let interestRate = 0.05 + // let years = 30 + // const name = "josh" + // let monthlyInterestRate = interestRate/12 + // let periods = years*12 + // const n1 = Math.pow((1 + monthlyInterestRate), periods) + // const numerator = principal * n1 * monthlyInterestRate + // const denominator = n1 - 1 + // let monthlyRate = numerator / denominator + // 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. @@ -55,6 +84,18 @@ For example, mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64 */ +function mortgageCalculator(principal, interestRate, years){ + const name = "josh" + let monthlyInterestRate = interestRate/12; + let periods = years*12; + const n1 = Math.pow((1 + monthlyInterestRate), periods); + const numerator = principal * n1 * monthlyInterestRate; + const denominator = n1 - 1; + let monthlyRate = numerator / denominator; + console.log(name+", your monthly rate is " + monthlyRate); +} + +mortgageCalculator(200000, 0.05, 30); @@ -67,6 +108,20 @@ 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 mortgageCalculator(principal, interestRate, years, creditScore){ + const name = "josh" + let monthlyInterestRate = interestRate/12; + let periods = years*12; + const n1 = Math.pow((1 + monthlyInterestRate), periods); + const numerator = principal * n1 * monthlyInterestRate; + const denominator = n1 - 1; + let monthlyRate = numerator / denominator; + console.log(name+", your monthly rate is " + monthlyRate); +} + +mortgageCalculator(200000, 0.05, 30, 675) + if (creditScore >= 740) + console.log("yes it is"); From 223d791864ad94c4da8ed62134086b9fe28c0447 Mon Sep 17 00:00:00 2001 From: josh jacquesj Date: Sat, 17 Oct 2020 14:01:20 -0500 Subject: [PATCH 2/4] finished task 5 --- index.js | 66 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/index.js b/index.js index da058e6c..18cb1366 100644 --- a/index.js +++ b/index.js @@ -84,44 +84,52 @@ For example, mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64 */ -function mortgageCalculator(principal, interestRate, years){ - const name = "josh" - let monthlyInterestRate = interestRate/12; - let periods = years*12; - const n1 = Math.pow((1 + monthlyInterestRate), periods); - const numerator = principal * n1 * monthlyInterestRate; - const denominator = n1 - 1; - let monthlyRate = numerator / denominator; - console.log(name+", your monthly rate is " + monthlyRate); -} - -mortgageCalculator(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). 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 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. +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 mortgageCalculator(principal, interestRate, years, creditScore){ +function mortgageCalculator(principal, interestRate, years, creditScore) { const name = "josh" - let monthlyInterestRate = interestRate/12; - let periods = years*12; - const n1 = Math.pow((1 + monthlyInterestRate), periods); - const numerator = principal * n1 * monthlyInterestRate; - const denominator = n1 - 1; - let monthlyRate = numerator / denominator; - console.log(name+", your monthly rate is " + monthlyRate); + let monthlyInterestRate = interestRate / 12 + let periods = years * 12 + const n1 = Math.pow((1 + monthlyInterestRate), periods) + const numerator = principal * n1 * monthlyInterestRate + const denominator = n1 - 1 + let monthlyRate = numerator / denominator + console.log(name + ", your monthly rate is " + monthlyRate) + console.log(creditScore) + if (creditScore > 740) + { + interestRate = interestRate * 0.95; + } + else if(creditScore < 660) + { + interestRate = interestRate * 1.05; + } + else (creditScore <= 740 && creditScore >= 660) + { + interestRate = interestRate; + } + console.log(interestRate) } -mortgageCalculator(200000, 0.05, 30, 675) - if (creditScore >= 740) - console.log("yes it is"); +mortgageCalculator(200000, 0.05, 30, 745); + + +// if (creditScore > 740); +// { +// interestRate = interestRate * 0.95; +// } +// elseif (creditScore <= 740 && interestRate >= 660) +// { +// monthlyRate = monthlyRate +// } elseif (creditScore < 660) +// { +// interestRate = interestRate * 1.05; +// }; From 5e8526bfca9df4e34468bc31b149a85bddffff02 Mon Sep 17 00:00:00 2001 From: josh jacquesj Date: Sat, 17 Oct 2020 16:26:24 -0500 Subject: [PATCH 3/4] still working on task 6 --- index.js | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 18cb1366..38ec86b7 100644 --- a/index.js +++ b/index.js @@ -119,18 +119,6 @@ function mortgageCalculator(principal, interestRate, years, creditScore) { mortgageCalculator(200000, 0.05, 30, 745); -// if (creditScore > 740); -// { -// interestRate = interestRate * 0.95; -// } -// elseif (creditScore <= 740 && interestRate >= 660) -// { -// monthlyRate = monthlyRate -// } elseif (creditScore < 660) -// { -// interestRate = interestRate * 1.05; -// }; - // 🏡 Task 6: Loops @@ -149,7 +137,39 @@ 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(principal, interestRate, years, creditScore) { + const name = "josh" + let monthlyInterestRate = interestRate / 12 + let periods = years * 12 + const n1 = Math.pow((1 + monthlyInterestRate), periods) + const numerator = principal * n1 * monthlyInterestRate + const denominator = n1 - 1 + let monthlyRate = numerator / denominator + console.log(name + ", your monthly rate is " + monthlyRate) + console.log(creditScore) + if (creditScore > 740) + { + monthlyRate = monthlyRate * 0.95; + } + else if(creditScore < 660) + { + monthlyRate = monthlyRate * 1.05; + } + else (creditScore <= 740 && creditScore >= 660) + { + monthlyRate = monthlyRate; + } + console.log(interestRate) + console.log(monthlyRate) + monthlyRate = interestRate * monthlyRate; + + for (interestRate = .02; interestRate < 10; interestRate += interestRate + .02) { + monthlyRate = interestRate * monthlyRate; + console.log(name + ", with an interest rate of " + interestRate + ", your monthly rate is " + monthlyRate) + } +} +variableInterestRate(200000, 0.04, 30, 602) // 🌟🌟🌟 STRETCH 🌟🌟🌟// From 273ce8cb89f59017a24964394a101a0aefc0aa5b Mon Sep 17 00:00:00 2001 From: josh jacques Date: Sun, 18 Oct 2020 11:04:39 -0500 Subject: [PATCH 4/4] still working on task 6... --- index.js | 77 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/index.js b/index.js index 38ec86b7..db7246c1 100644 --- a/index.js +++ b/index.js @@ -22,8 +22,6 @@ let name = "josh" let monthlyInterestRate = interestRate / 12 let periods = years * 12 -// console.log (monthlyInterestRate) -// console.log (periods) @@ -61,21 +59,21 @@ console.log(monthlyRate); 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 = "josh" - // let monthlyInterestRate = interestRate/12 - // let periods = years*12 - // const n1 = Math.pow((1 + monthlyInterestRate), periods) - // const numerator = principal * n1 * monthlyInterestRate - // const denominator = n1 - 1 - // let monthlyRate = numerator / denominator - // console.log(name+", your monthly rate is " + monthlyRate); - // } - - // mortgageCalculator() + function mortgageCalculator(){ + let principal = 200000 + let interestRate = 0.05 + let years = 30 + const name = "josh" + let monthlyInterestRate = interestRate/12 + let periods = years*12 + const n1 = Math.pow((1 + monthlyInterestRate), periods) + const numerator = principal * n1 * monthlyInterestRate + const denominator = n1 - 1 + let monthlyRate = numerator / denominator + 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. @@ -84,13 +82,30 @@ For example, mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64 */ +function mortgageCalculator(principal, interestRate, years){ + const name = "josh" + let monthlyInterestRate = interestRate/12; + let periods = years*12; + const n1 = Math.pow((1 + monthlyInterestRate), periods); + const numerator = principal * n1 * monthlyInterestRate; + const denominator = n1 - 1; + let monthlyRate = numerator / denominator; + console.log(name+", your monthly rate is " + monthlyRate); +} + +mortgageCalculator(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). 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 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. +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 mortgageCalculator(principal, interestRate, years, creditScore) { const name = "josh" let monthlyInterestRate = interestRate / 12 @@ -100,26 +115,21 @@ function mortgageCalculator(principal, interestRate, years, creditScore) { const denominator = n1 - 1 let monthlyRate = numerator / denominator console.log(name + ", your monthly rate is " + monthlyRate) - console.log(creditScore) if (creditScore > 740) { - interestRate = interestRate * 0.95; + interestRate = monthlyRate * 0.95; } else if(creditScore < 660) { - interestRate = interestRate * 1.05; + interestRate = monthlyRate * 1.05; } else (creditScore <= 740 && creditScore >= 660) { interestRate = interestRate; } - console.log(interestRate) } -mortgageCalculator(200000, 0.05, 30, 745); - - - +mortgageCalculator(200000, 0.05, 30, 750); // 🏡 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. @@ -136,8 +146,7 @@ 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(principal, interestRate, years, creditScore) { +function mortgageCalculator(principal, interestRate, years, creditScore) { const name = "josh" let monthlyInterestRate = interestRate / 12 let periods = years * 12 @@ -146,7 +155,6 @@ function variableInterestRate(principal, interestRate, years, creditScore) { const denominator = n1 - 1 let monthlyRate = numerator / denominator console.log(name + ", your monthly rate is " + monthlyRate) - console.log(creditScore) if (creditScore > 740) { monthlyRate = monthlyRate * 0.95; @@ -159,18 +167,11 @@ function variableInterestRate(principal, interestRate, years, creditScore) { { monthlyRate = monthlyRate; } - console.log(interestRate) - console.log(monthlyRate) - monthlyRate = interestRate * monthlyRate; - - for (interestRate = .02; interestRate < 10; interestRate += interestRate + .02) { - monthlyRate = interestRate * monthlyRate; - console.log(name + ", with an interest rate of " + interestRate + ", your monthly rate is " + monthlyRate) - } } -variableInterestRate(200000, 0.04, 30, 602) +mortgageCalculator(200000, 0.05, 30, 750); +for (monthlyInterestRate = .02; monthlyInterestRate <=0.06; monthlyInterestRate += 0.05) // 🌟🌟🌟 STRETCH 🌟🌟🌟//