Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,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 year = 30;
let name = 'gregory';



Expand All @@ -15,7 +18,8 @@ Create a variable called `monthlyInterestRate` and give it the value of interest

Create another variable called `periods` and give it the value of years*12.
*/

let monthlyInterestRate = interestRate / 12;
let periods = year * 12;



Expand All @@ -27,18 +31,27 @@ Hint: while these calculations can be done in one line, it might be helpful to c
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
*/
monthlyInterestRate = periods[i(1 + i) ^ N] / [(1 + i) ^ N - 1]
// */



var numerator = monthlyInterestRate * Math.pow((1 + monthlyInterestRate), periods)
var denominator = Math.pow((1 + monthlyInterestRate), periods) - 1;
var monthlyRate = numerator / denominator * principal;
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}"

If your name is `Oscar` mortgageCalculator() should return "Oscar, your monthly rate is 1073.64"
*/
function mortgageCalculator() {
return name + ',your monthly rate is' + monthlyRate;
}


console.log(mortgageCalculator());



Expand All @@ -48,9 +61,11 @@ If your name is `Oscar` mortgageCalculator() should return "Oscar, your monthly
For example,
mortgageCalculator(2000000, 0.05, 30); <-- should return 1,073.64
*/
function mortgageCalculator(P, I, N) {
return (Math.round(P * (((I / 12) * Math.pow((1 + (I / 12)), (N * 12))) / (Math.pow((1 + (I / 12)), (N * 12)) - 1)) * 100) / 100)
}



console.log(mortgageCalculator(2000000, 0.05, 30));


// 🏡 Task 5: Conditionals
Expand Down Expand Up @@ -94,4 +109,4 @@ For example, variableInterestRate(200000, 0.04, 30) should console.log:
/* 🏡 Explore using `window.prompt()` to allow a user to input parameters in the browser */


/* 🏡 Refactor your `variableInterestRate()` function to accept an array of interest rates (make sure to copy and paste as to not lose your work!) */
/* 🏡 Refactor your `variableInterestRate()` function to accept an array of interest rates (make sure to copy and paste as to not lose your work!) */