diff --git a/index.js b/index.js index 667af155..7d01f35f 100644 --- a/index.js +++ b/index.js @@ -4,8 +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 = 'OrlandoTaylor'; // 🏡 Task 1.5: Simple Math @@ -15,8 +17,8 @@ (2) Create another variable called `periods` and give it the value of years*12. */ - - +let monthlyInterestRate = interestRate / 12; +let periods = years * 12; // 🏡 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. @@ -35,6 +37,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 = principal * n1 * monthlyInterestRate; +let denominator = n1 - 1; +let monthlyRate = numerator / denominator; @@ -44,9 +50,24 @@ 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, name) { + let interestRate = 0.05; + let years = 30; + + 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; + return `${name}, your monthly rate is ${monthlyRate}.`; +} + //test case + var output = mortgageCalculator("Oscar"); + console.log(output); // 🏡 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,9 +76,26 @@ For example, mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64 */ +function mortgageCalculator (principal, interestRate, years) { + let principal = 200000; + let interestRate = 0.05; + let years = 30; + let name = 'OrlandoTaylor'; + + 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; + return `${name}, your monthly rate is ${monthlyRate}.`; +} + //test case + var output = mortgageCalculator(200000, 0.05, 30); + console.log(output); // 🏡 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).