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
83 changes: 76 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
// 🌟🌟🌟 M V P 🌟🌟🌟//
console.log('hello world')

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


let name = 'yvette';
console.log(name)

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

*/


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





// 🏡 Task 2: Harder Math
Expand All @@ -27,8 +41,21 @@ Hint: while these calculations can be done in one line, it might be helpful to c
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
M = P [ I ( 1 + I )^N ] / [ ( 1 + I )^N – 1 ]
```
In order to find your monthly payment amount "M,” you need to plug in the following three numbers from your loan:
`P` = Principal amount (the total amount borrowed)
`I` = Interest rate on the mortgage
`N` = Number of periods (monthly mortgage payments)
Exercises outlined in the `index.js` file walk you through a series of steps for building a robust and functional mortgage calculator.
Check out the resources below for more of a step-by-step walk-through of this math, and to see a well-designed mortgage calculator web app. Believe it or not, the backend you write today could power a beautiful site like that!

*/

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



Expand All @@ -37,10 +64,19 @@ 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 mortgageCalculato (principal,numerator,denominator) {
console.log((principal*numerator)/(denominator))*/




/*const mortgageCalculator = function(principal,numerator,denominator) {
console.log((principal*(numerator))/(denominator))
if (name === 'Oscar') {
return 'Oscar, your monthly rate is 1073.64';}
}*/
function mortgageCalculator (){
let = name + monthlyRate + monthlyRate ;
return bill;
}

// 🏡 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.
Expand All @@ -49,15 +85,37 @@ For example,
mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64
*/

const divide = function (principal, numerator, denominator ) {
return (principal * numerator) / denominator ;
}
console.log(mortgageCalculator(principal, numerator, denominator ));



/*console.log
function divide (multiplicate, denominator) {

return multiplicate / denominator ;
}
console.log ()*/



// 🏡 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 mortgageCalculator(principal, interestRate, years, creditScore)

if (creditScore > 740){
interestRate = 0.05;
}
else if (creditScore < 660 ){
interestRate <= 0.05;
}

console.log (mortgageCalculator(principal, interestRate, years, creditScore));



Expand All @@ -77,9 +135,19 @@ 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"
*/




let principal = P ;
let years = N ;
let interestRate = I ;

function variableInterestRate (P,N,I) {
let = name + 'with an intereset rate of' + monthlyRate ;
return
for (let i=0; i<(P,N,I).length; i++){
if (((P,N,I)[i])=== 0.005 || ((P,N,I)[i]) - 0.02) {
return `&{Name}, with an with an interest rate of ${}
}
}

// 🌟🌟🌟 STRETCH 🌟🌟🌟//

Expand All @@ -94,4 +162,5 @@ For example, variableInterestRate(200000, 0.04, 30) should console.log:
/* 🏡 Explore using `window.prompt()` to allow a user to input parameters in the browser */


/* 🏡 Refactor your `variableInterestRate()` function to accept an array of interest rates (make sure to copy and paste as to not lose your work!) */
/* 🏡 Refactor your `variableInterestRate()` function to accept an array of interest rates (make sure to copy and paste as to not lose your work!)*/