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
37 changes: 36 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
// 🏡 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;
const years = 30;
const name = 'Jayvon';



Expand All @@ -16,6 +19,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.
*/

monthlyInterestRate = interestRate/12
periods = years*12



Expand All @@ -29,7 +34,12 @@ 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 + nmonthlyinterestRate), periods);
let denominator = Math.pow((1 + monthlyinterestRate),periods) -1;


let monthlyRate = principal * (numerator/denominator);
console.log(monthlyRate)


// 🏡 Task 3: Function
Expand All @@ -38,8 +48,15 @@ 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(principal, interest, numberOfPeriods){
let monthlyInterestRate = interest / 12;
let periods = numberOfPeriods * 12;
let numerator = monthlyInterestRate * Math.pow(1 + monthlyInterestRate), periods;
let denominator = Math.pow(1 + monthlyInterestRate), periods) -1;

let monthlyRate = principal * (numerator/denominator);

return 'Jayvon, your monthly rate is $(monthlyRate)'


// 🏡 Task 4: Arguments and Parameters
Expand All @@ -49,7 +66,25 @@ For example,
mortgageCalculator(2000000, 0.05, 30); <-- should return 1,073.64
*/

function mortgageCalculator(principal, interest, years, creditScore){
let adjustedInterest = interest;

if(creditScore > 740){
adjustedInterest = adjustedInterest - 0.005;
} else if (creditScore < 600){
adjustedInterest = adjustedInterest + 0.005;
}

let monthlyInterestRate = adjustedInterest / 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);

return 'Jayvon, your monthly rate is ${ monthlyRate}';

console.log(mortgageCalculator(30000, 0.06, 30, 800))



Expand Down