Skip to content

Brandon Alverson-MPV #49

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
60 changes: 55 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
// 🏡 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 creditScore = 720;
const name = 'Brandon';



Expand All @@ -14,7 +18,8 @@
(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 = (I / 12);
// let periods = (N * 12);



Expand All @@ -34,15 +39,40 @@ 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 = (P * n1 * monthlyInterestRate);
// let denominator = (n1 -1);
// let 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(principal, interestRate, years, creditScore)
{
let monthlyInterestRate = (interestRate / 12);
let periods = (years * 12);
let n1 = Math.pow((1 + monthlyInterestRate) , periods);
let numerator = (principal * n1 * monthlyInterestRate);
let denominator = (n1 - 1);
let monthlyRate = (numerator / denominator);
if (creditScore > 740) {
interestRate = (interestRate * 0.95);
}
else if (creditScore < 660) {
interestRate = (interestRate * 1.05);
}
else {
interestRate = interestRate;
}

// console.log (name + ', your monthly rate is $' + (monthlyRate).toFixed(2));

return monthlyRate;
}
mortgageCalculator(200000, 0.05, 30, 700);



Expand All @@ -55,6 +85,7 @@ For example,
mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64
*/

mortgageCalculator(200000, 0.05, 30, 650);



Expand All @@ -67,7 +98,7 @@ 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.
*/


// COMPLETE


// 🏡 Task 6: Loops
Expand All @@ -86,6 +117,25 @@ For example, variableInterestRate(200000, 0.04, 30) should console.log:
"{Name}, with an interest rate of 0.06, your monthly rate is $1199"
*/

function variableInterestRate(principal, interestRate, years, creditScore) {
if (creditScore > 740) {
interestRate = (interestRate * 0.95);
}
else if (creditScore < 660) {
interestRate = (interestRate * 1.05);
}
else {
interestRate = interestRate;
}
let variableInterest= interestRate - .02;
for (i= 1; i < 10; i++){
let monthlyRate = mortgageCalculator(principal, variableInterest, years, creditScore);
console.log (name + ', at an interest rate of ' + variableInterest.toFixed(3) + ", your monthly rate is $" + monthlyRate.toFixed(0));
variableInterest += 0.005;
}
}

variableInterestRate(200000, 0.04, 30, 700);



Expand Down