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
89 changes: 89 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
/* 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 interest = 0.05;

let years = 30;

let name = 'Candace';


// 🏡 Task 1.5: Simple Math
Expand All @@ -16,6 +21,9 @@ 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 = interest / 12;

let periods = years * 12;



Expand All @@ -29,6 +37,13 @@ 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 numerator = monthlyInterestRate * (Math.pow((1 + monthlyInterestRate), periods));
console.log("numerator", numerator)
let denominator = (Math.pow((1 + monthlyInterestRate), periods)) - 1;
console.log("denominator", denominator)
let monthlyRate = principal * (numerator / denominator);

console.log("1073.64 =>", monthlyRate)



Expand All @@ -37,8 +52,23 @@ 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() {
// let principal = 200000;
// let interest = 0.05;
// let years = 30;
// let name = 'Candace';

// let monthlyInterestRate = interest / 12;
// let periods = years * 12;

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

// console.log(`${name}, your monthly rate is ${monthlyRate}`)
// }

// mortgageCalculator();



Expand All @@ -48,9 +78,23 @@ If your name is `Oscar` mortgageCalculator() should return "Oscar, your monthly
For example,
mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64
*/
// function mortgageCalculator(p, i, y) {
// let principal = p;
// let interest = i;
// let years = y;
// let name = 'Candace';

// let monthlyInterestRate = interest / 12;
// let periods = years * 12;

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

// console.log(`${name}, your monthly rate is ${monthlyRate}`)
// }

// mortgageCalculator(200000, 0.05, 30);


// 🏡 Task 5: Conditionals
Expand All @@ -59,7 +103,31 @@ 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.
*/

function mortgageCalculator(p, i, y, c) {
let principal = p;
let interest = i;
let years = y;
let name = 'Candace';

if (c < 660) {
interest = interest + 0.5;
} else if (c > 740) {
interest = interest - 0.5;
}

let monthlyInterestRate = interest / 12;
let periods = years * 12;

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

console.log(`${name}, your monthly rate is ${monthlyRate}`)
}

mortgageCalculator(200000, 0.05, 30, 650);
mortgageCalculator(200000, 0.05, 30, 700);
mortgageCalculator(200000, 0.05, 30, 750);


// 🏡 Task 6: Loops
Expand All @@ -77,6 +145,27 @@ For example, variableInterestRate(200000, 0.04, 30) should console.log:
"{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"
*/
function variableInterestRate(n, p, tempI, y) {
for(let i = 0; i<10;i++) {
let principal = p;
let interest = tempI;
let years = y;
let name = n;

interest = interest + i*.005;

let monthlyInterestRate = interest / 12;
let periods = years * 12;

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

console.log(`${name}, with an interest rate of ${interest}, your monthly rate is ${monthlyRate}`)
}
}

variableInterestRate("Candace", 200000, 0.04, 30);



Expand Down