diff --git a/index.js b/index.js index 667af155..0618f0c4 100644 --- a/index.js +++ b/index.js @@ -3,8 +3,17 @@ // 🏡 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; +console.log(principal); +let interestRate = 0.05; +console.log(interestRate); +let years = 30; +console.log(years); + +const name = 'Mariam'; +console.log(name); @@ -14,7 +23,12 @@ (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; + console.log(monthlyInterestRate); + + let periods = years * 12; +console.log(periods); @@ -35,8 +49,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 */ - - + + function calculator(P,I,N){ + let n1 = Math.pow(1 + I/12,periods); + let numerator = [P * (n1 * I/12)]; + let denominator = (n1 - 1); + let monthlyRate = (numerator / denominator).toFixed(2); + console.log(monthlyRate); + return 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}" @@ -45,6 +66,16 @@ If your name is `Oscar` mortgageCalculator() should return "Oscar, your monthly */ +function mortgageCalculator(P,I,N,creditScore){ + if (creditScore>740){ + I=I-0.05 + } + rate = calculator(P,I,N) + let string = ', your monthly rate is $' + teststring=`${name}, your monthly rate is $${rate}` + return teststring; +} +console.log(mortgageCalculator(200000, 0.05, 30)); @@ -58,7 +89,6 @@ mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64 - // 🏡 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). @@ -66,7 +96,25 @@ 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. */ - +/*var mortgageCalculator = function(P, I, N, creditScore){ + let creditScore= (<= 800); + let p = (200000); + let i = (0.05 / 12); + let n = (30 * 12); + let n1 = (1 + i) ** n; + let numerator = [p * (n1 * i)]; + let denominator = (n1 - 1); + let monthlyRate = (numerator / denominator); + console.log(monthlyRate); + return [P*[(1+I/12)**N]*(I/12)] / ([(1+I/12)**N]-1)}; +console.log(mortgageCalculator(200000, 0.05, 30)); +let ___=___; +let ___=___; +if (___=___); +{____=____}; +else if (___=___)_; +{_____=___} +else console.log{___};*/ @@ -86,7 +134,19 @@ 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(P,I,N){ + /*loop that increases I by .5% ten times*/ + /*inside the loop run lines 140 through 143*/ + I=Math.round((I-0.02)*1000)/1000; + for (let i = 0; i < 10; i++){ + I = Math.round((I + 0.005)*1000)/1000; + console.log(`logging I: ${I}`) + rate = calculator(P,I,N) + teststring=`${name}, with an interest rate of ${I}, your monthly rate is $${rate}` + console.log(teststring); +} +} +console.log(variableInterestRate(200000, 0.04, 30)); // 🌟🌟🌟 STRETCH 🌟🌟🌟//