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
166 changes: 138 additions & 28 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,149 @@
// 🌟🌟🌟 M V P 🌟🌟🌟//
// // 🌟🌟🌟 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.
*/
// // 🏡 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 because this value will change as payments are made
let interestRate = 0.05;
let years = 30;
let name = 'Vickie'; //because name may change

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

// Create a variable called `monthlyInterestRate` and give it the value of interest rate divided by 12.

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

// 🏡 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.
const monthlyInterestRate = (interestRate/12);

Create a variable called `monthlyInterestRate` and give it the value of interest rate divided by 12.
const periods = (years*12);

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

// // 🏡 Task 2: Harder Math
// /* Create your calculator! Use the formula in the ReadMe to run calculations on your numbers. Save the final value into a variable called monthlyRate.

// Hint: while these calculations can be done in one line, it might be helpful to create a variable called "numerator" to calculate the numerator, and another called "denominator" to calculate the denominator

// Hint #2: you'll need to use the `math` object for parts of this calculation!

// 🏡 Task 2: Harder Math
/* Create your calculator! Use the formula in the ReadMe to run calculations on your numbers. Save the final value into a variable called monthlyRate.
// When your math is correct, monthlyRate will equal 1073.64
// */

Hint: while these calculations can be done in one line, it might be helpful to create a variable called "numerator" to calculate the numerator, and another called "denominator" to calculate the denominator
const numerator = monthlyInterestRate*(Math.pow((1+monthlyInterestRate), periods));

Hint #2: you'll need to use the `math` object for parts of this calculation!
const denominator = ((Math.pow((1+monthlyInterestRate), periods))-1);

When your math is correct, monthlyRate will equal 1073.64
*/
const monthlyRate = principal*(numerator/denominator);

//this is a new function made to calculate mortgage

function mortgageEquate (principal, interestRate, years){

let monthlyInterestRate = (interestRate/12);
let periods = (years*12);
const numerator = monthlyInterestRate*(Math.pow((1+monthlyInterestRate), periods));
const denominator = ((Math.pow((1+monthlyInterestRate), periods))-1);
const monthlypayment = principal*(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}"
return monthlypayment;
}
console.log(mortgageEquate(200000, .05,30));

If your name is `Oscar` mortgageCalculator() should return "Oscar, your monthly rate is 1073.64"
*/




// // 🏡 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}"

// 🏡 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.
// If your name is `Oscar` mortgageCalculator() should return "Oscar, your monthly rate is 1073.64"
// */

For example,
mortgageCalculator(2000000, 0.05, 30); <-- should return 1,073.64
*/
// //variables used // the variables
// // let principal = 200000; //let because this value will change as payments are made
// // const interestRate = 0.05;
// // const years = 30;
// // let name = 'Vickie'; //because name may change
// // const monthlyInterestRate = (interestRate/12);
// // const periods = (years*12);
// // const numerator = interestRate*(Math.pow((1+interestRate), periods));
// // const denominator = ((Math.pow((1+interestRate), periods))-1);
// // const monthlyRate = principal*(numerator/denominator);


// //creating the function

function mortgageCalculator(){

//(original code not needed as new function was created)
// const numerator = monthlyInterestRate*(Math.pow((1+monthlyInterestRate), periods));
// const denominator = ((Math.pow((1+monthlyInterestRate), periods))-1);
// const monthlyRate = principal*(numerator/denominator);

// 🏡 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).
let x = mortgageEquate(principal, interestRate, years);//calls function code from above

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.
*/
//the console.log return
console.log(name+", your monthly rate is "+x);

// console.log( "Calcualtor 1" );

}


// //call the function to run code
mortgageCalculator();


// // 🏡 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(2000000, 0.05, 30); <-- should return 1,073.64
// */

function mortgageCalculator2(P, I, N){

let x = mortgageEquate (P, I, N);
// //the console.log return

console.log(name+', your monthly rate is '+x);
// console.log( "Calculator 2" );

}
// //call the function to run code
mortgageCalculator2(200000, 0.05, 20);



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

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

function mortgageCalculator3 (P,I,N,score){

if (score>740 && score<800) {
I = (I - .005);
}

else if (score<660) {
I = (I + .005);
}


// console.log(I);
//if i was stopping here but...

//this calculates new payment
let x = mortgageEquate (P,I,N);
console.log(name+', your monthly rate is '+x);
}

mortgageCalculator3 (2000000, 0.05, 30, 700);

// 🏡 Task 6: Loops
/* Write a new function called variableInterestRate. This function should be the same as mortgageCalculator, except it should console.log the monthly payment for 10 different interest rates at 0.5% increments plus or minus 2% from the inputted interest rate. Complete these calculations using a for loop.
Expand All @@ -79,6 +162,33 @@ For example, variableInterestRate(200000, 0.04, 30) should console.log:
*/


function variableInterestRate (P,I,N){

I = I - .02;
for (let i = 0; i<10; i++){

let y = mortgageEquate (P,I,N);
I = (I+.005);
I = Math.round(I*1000)/1000;


console.log(name+', with an interest rate of '+I+', your monthly rate is '+y);
}
}

variableInterestRate (200000, .04, 30);














// 🌟🌟🌟 STRETCH 🌟🌟🌟//
Expand Down