diff --git a/index.js b/index.js index 667af155..7ee6dfcf 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,11 @@ // 🏡 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 creditScore = 720; +const name = 'Brandon'; @@ -14,7 +18,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 = (I / 12); +// let periods = (N * 12); @@ -34,8 +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 = (P * n1 * monthlyInterestRate); +// let denominator = (n1 -1); +// let monthlyRate = (numerator / denominator); // 🏡 Task 3: Function @@ -43,6 +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(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; + } + +// console.log (name + ', your monthly rate is $' + (monthlyRate).toFixed(2)); + + return monthlyRate; +} +mortgageCalculator(200000, 0.05, 30, 700); @@ -55,6 +85,7 @@ For example, mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64 */ +mortgageCalculator(200000, 0.05, 30, 650); @@ -67,7 +98,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 @@ -86,6 +117,25 @@ 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) { + 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; + } +} + +variableInterestRate(200000, 0.04, 30, 700);