|
4 | 4 | /* 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.
|
5 | 5 | */
|
6 | 6 |
|
7 |
| - |
8 |
| - |
9 |
| - |
10 |
| - |
11 | 7 | // 🏡 Task 1.5: Simple Math
|
12 | 8 | /* To create a monthly mortgage rate calculator, we need to know the number of years in months and the monthly interest rate.
|
13 | 9 |
|
|
16 | 12 | */
|
17 | 13 |
|
18 | 14 |
|
19 |
| - |
20 |
| - |
21 | 15 | // 🏡 Task 2: Harder Math
|
22 | 16 | /* 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.
|
23 | 17 |
|
@@ -103,3 +97,32 @@ For example, variableInterestRate(200000, 0.04, 30) should console.log:
|
103 | 97 |
|
104 | 98 |
|
105 | 99 | /* 🏡 Refactor your `variableInterestRate()` function to accept an array of interest rates (make sure to copy and paste as to not lose your work!) */
|
| 100 | + |
| 101 | + function mortgageCalculator(principal, interestRate, years, creditScore){ |
| 102 | + const name = "Ally"; |
| 103 | + let monthlyInterestRate = ( interestRate / 12 ) |
| 104 | + let periods = ( years * 12 ) |
| 105 | + let i = monthlyRate |
| 106 | + |
| 107 | + let variableInterestRate = ( monthlyRate * 0.95 ) |
| 108 | + for (let i = 0; i < 10; i + 0.95) { |
| 109 | + console.log(name + ",with an interest rate of" + monthlyInterestRate + "your monthly rate is" + variableInterestRate + "<br>") |
| 110 | + } |
| 111 | + let n1 = Math.pow((1 + monthlyInterestRate ) **periods ) |
| 112 | + let numerator = principal * n1 * monthlyInterestRate |
| 113 | + let denominator = n1 - 1 |
| 114 | + let monthlyRate = numerator/denominator |
| 115 | + |
| 116 | + } |
| 117 | + if (creditScore > 740 ) { monthlyRate = (monthlyRate * 0.95); |
| 118 | + } |
| 119 | + else if (creditScore < 660 ) {monthlyRate = (monthlyRate * 1.05); |
| 120 | + } |
| 121 | + else if (creditScore <= 740 && creditScore >= 660) {monthlyRate = monthlyRate}; |
| 122 | + } |
| 123 | + console.log(name + "your monthly rate is" + monthlyRate)} |
| 124 | +} |
| 125 | + |
| 126 | + mortgageCalculator( 200000, 0.05, 30, 700) |
| 127 | +} |
| 128 | + |
0 commit comments