Skip to content

Mariam Addy #55

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 3 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
70 changes: 65 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@
// 🏡 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;
console.log(principal);

let interestRate = 0.05;
console.log(interestRate);

let years = 30;
console.log(years);

const name = 'Mariam';
console.log(name);



Expand All @@ -14,7 +23,12 @@
(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;
console.log(monthlyInterestRate);


let periods = years * 12;
console.log(periods);



Expand All @@ -35,8 +49,15 @@ 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
*/




function calculator(P,I,N){
let n1 = Math.pow(1 + I/12,periods);
let numerator = [P * (n1 * I/12)];
let denominator = (n1 - 1);
let monthlyRate = (numerator / denominator).toFixed(2);
console.log(monthlyRate);
return 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}"
Expand All @@ -45,6 +66,16 @@ If your name is `Oscar` mortgageCalculator() should return "Oscar, your monthly
*/


function mortgageCalculator(P,I,N,creditScore){
if (creditScore>740){
I=I-0.05
}
rate = calculator(P,I,N)
let string = ', your monthly rate is $'
teststring=`${name}, your monthly rate is $${rate}`
return teststring;
}
console.log(mortgageCalculator(200000, 0.05, 30));



Expand All @@ -58,15 +89,32 @@ mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64




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

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

/*var mortgageCalculator = function(P, I, N, creditScore){
let creditScore= (<= 800);
let p = (200000);
let i = (0.05 / 12);
let n = (30 * 12);
let n1 = (1 + i) ** n;
let numerator = [p * (n1 * i)];
let denominator = (n1 - 1);
let monthlyRate = (numerator / denominator);
console.log(monthlyRate);
return [P*[(1+I/12)**N]*(I/12)] / ([(1+I/12)**N]-1)};
console.log(mortgageCalculator(200000, 0.05, 30));
let ___=___;
let ___=___;
if (___=___);
{____=____};
else if (___=___)_;
{_____=___}
else console.log{___};*/



Expand All @@ -86,7 +134,19 @@ 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(P,I,N){
/*loop that increases I by .5% ten times*/
/*inside the loop run lines 140 through 143*/
I=Math.round((I-0.02)*1000)/1000;
for (let i = 0; i < 10; i++){
I = Math.round((I + 0.005)*1000)/1000;
console.log(`logging I: ${I}`)
rate = calculator(P,I,N)
teststring=`${name}, with an interest rate of ${I}, your monthly rate is $${rate}`
console.log(teststring);
}
}
console.log(variableInterestRate(200000, 0.04, 30));


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