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
79 changes: 71 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,28 @@
/* 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.
*/

/*var principal = 200000;

var interestRate = .05;

var years = 30;

var name = "Denis";

// 🏡 Task 1.5: Simple Math
/* To create a monthly mortgage rate calculator, we need to know the number of years in months and the monthly interest rate.
/* To create a monthly mortgage rate calculator, we need to know the number of years in months and the monthly interest rate.

(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.
*/
(1) Create a variable called `monthlyInterestRate` and give it the value of interest rate divided by 12.

var monthlyInterestRate = interestRate/12;

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

var 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.
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.

M = P [ I ( 1 + I )^N ] / [ ( 1 + I )^N – 1 ]

Expand All @@ -36,28 +42,51 @@ When your math is correct, monthlyRate will equal 1073.64
*/


/* var n1 = (1 + monthlyInterestRate)**periods;

var numerator = principal * n1 * monthlyInterestRate;
var denominator = n1 - 1;

var monthlyRate = numerator/denominator;*/

// 🏡 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()
{
console.log(name,"your monthly rate is $"+monthlyRate);
}*/

// 🏡 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.

For example,
mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64
*/
/*
function mortgageCalculator(principal, interestRate, years) {
var monthlyInterestRate = interestRate/12;
var periods = years*12;

var n1 = (1 + monthlyInterestRate)**periods;

var numerator = principal * n1 * monthlyInterestRate;
var denominator = n1 - 1;

var monthlyRate = numerator/denominator;

return monthlyRate;
}

let x = mortgageCalculator(200000,.05,30);

let y = x.toFixed(2);

console.log(y);
*/

// 🏡 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).
Expand All @@ -67,6 +96,39 @@ 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.
*/

function mortgageCalculator(principal, interestRate, years, creditScore) {

var monthlyInterestRate = interestRate/12;
var periods = years*12;

var n1 = (1 + monthlyInterestRate)**periods;

var numerator = principal * n1 * monthlyInterestRate;
var denominator = n1 - 1;

var monthlyRate = numerator/denominator;

var creditScore;

if (creditScore < 660) {
realMonthlyRate = monthlyRate * .95;
}
else if (creditScore > 740) {
realMonthlyRate = monthlyRate * 1.05;
}
else {
realMonthlyRate = monthlyRate;
}

return realMonthlyRate;
}

let x = mortgageCalculator(200000,.05,30, 780);

let y = x.toFixed(2);

console.log(y);




Expand All @@ -89,6 +151,7 @@ For example, variableInterestRate(200000, 0.04, 30) should console.log:




// 🌟🌟🌟 STRETCH 🌟🌟🌟//

/* Attempt any of the stretch goals below once you have finished the work above. Remember as always, these may require additional research beyond what you learned today */
Expand Down