Skip to content

Tony miller #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
124 changes: 105 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
// 🌟🌟🌟 M V P 🌟🌟🌟//

// 🏡 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 years = 30;
let name = 'Tony Miller';
// 🏡 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.

(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;
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.
/* 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 ]
//M = principle [ interestRate ( 1 + interestRate )^periods ] / [ ( 1 + interestRate )^periods - 1 ]

Hint: while these calculations can be done in one line, it might be helpful to create seperate variables to hold parts of your equation. That might look like this:
//M = P [ I ( 1 + I )^N ] / [ ( 1 + I )^N – 1 ]
/*Hint: while these calculations can be done in one line, it might be helpful to create seperate variables to hold parts of your equation. That might look like this:

(1) Create a variable called n1 and set it equal to (1 + monthlyInterestRate )^N
(2) Create a variable called numerator and set it equal to p * n1 * monthlyInterestRate
Expand All @@ -35,17 +32,35 @@ 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;
//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(name, principle)
{
//let principal = 200000;
let interestRate = 0.05;
let years = 30;
//let name = 'Tony';
let monthlyInterestRate = interestRate / 12;
let periods = years * 12;
let n1 = Math.pow((1 + monthlyInterestRate), periods);
let numerator = principle * n1 * monthlyInterestRate;
let denominator = n1 - 1;
let monthlyRate = numerator / denominator;

return `${name}, your monthly rate is ${monthlyRate}`;
}
//var output = mortgageCalculator('oscar', 200000);
//console.log(output);


// 🏡 Task 4: Arguments and Parameters
Expand All @@ -55,6 +70,26 @@ For example,
mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64
*/

function mortgageCalculator(name, principle, interestRate, years)
{
//let principal = 200000;
//let interestRate = 0.05;
//let years = 30;
//let name = 'Tony';
let monthlyInterestRate = interestRate / 12;
let periods = years * 12;
let n1 = Math.pow((1 + monthlyInterestRate), periods);
let numerator = principle * n1 * monthlyInterestRate;
let denominator = n1 - 1;
let monthlyRate = numerator / denominator;

return `${name}, your monthly rate is ${monthlyRate}`;
}
//var output = mortgageCalculator('oscar', 200000);
//console.log(output);






Expand All @@ -64,9 +99,38 @@ mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64

Then, add control flow within your function such that IF creditScore is above 740, interest rate drops by 0.5%, if credit score is below 660, interest rate increases by 0.5% and if credit score is anywhere between 660 and 740 interest rate doesn't change.

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.
Hint: To drop an interest rate by 5% you can take monthlyRate and multiply it by 0.05. Similarly, to increase an interest rate by 5% you'd do monthlyRate * 1.05.
*/

function mortgageCalculator(name, principle, interestRate, years, creditScore)
{
//let principal = 200000;
//let interestRate = 0.05;
//let years = 30;
//let name = 'Tony';
let monthlyInterestRate = interestRate / 12;
let periods = years * 12;

if (creditScore > 740) {
monthlyInterestRate = monthlyInterestRate * 0.95;

} else if (creditScore < 600) {
monthlyInterestRate = monthlyInterestRate * 1.05;

} else if (creditScore >= 600 && creditScore <= 740) {

}
let n1 = Math.pow((1 + monthlyInterestRate), periods);
let numerator = principle * n1 * monthlyInterestRate;
let denominator = n1 - 1;
let monthlyRate = numerator / denominator;


return `${name}, your monthly rate is ${monthlyRate}`;
}
var output = mortgageCalculator('oscar', 200000, 0.05, 30, 800);
//console.log(output);




Expand All @@ -84,7 +148,28 @@ For example, variableInterestRate(200000, 0.04, 30) should console.log:
"{Name}, with an interest rate of 0.05, your monthly rate is $1074"
"{Name}, with an interest rate of 0.055, your monthly rate is $1136"
"{Name}, with an interest rate of 0.06, your monthly rate is $1199"
*/
*/
const variableInterestRate = function (name, principal, interestRate, years) {

//for loop engine using interestRate as the counter
for (let i = interestRate - 0.02; i<= interestRate + 0.02; i += 0.005 )

{//for loop beginning
//set variable values
let monthlyInterestRate = i/12;
let periods = years*12;

//formula
let n1 = Math.pow(1 + monthlyInterestRate, periods);
let numerator = principal * n1 * monthlyInterestRate;
let denominator = n1 -1;
let monthlyRate = numerator/denominator;

//output with consolidated rounders.
console.log (`${name}, with an interest rate of ${i.toFixed(3)}, your monthly rate is $${Math.round(monthlyRate)}`);
}
}
variableInterestRate ('Tony', 200000, 0.04, 30);



Expand All @@ -103,3 +188,4 @@ For example, variableInterestRate(200000, 0.04, 30) should console.log:


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