From 8637a5929e8a262887790159c29e9701be3354e4 Mon Sep 17 00:00:00 2001 From: shanon <13fritsh@gmail.com> Date: Wed, 13 May 2020 20:02:40 -0500 Subject: [PATCH 1/2] answered 1-5 was really focused on trying to get things to work that i forgot to add commit and push sorry still have 6 to do --- index.js | 71 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 61 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index eb1b3036..2ac02eb4 100644 --- a/index.js +++ b/index.js @@ -3,9 +3,16 @@ // 🏡 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 insterestRate = 0.05025; +// let years = 30; +// const name = 'Shanon'; - - +// console.log(principal); +// console.log(insterestRate); +// console.log(years); +// console.log(name); // 🏡 Task 1.5: Simple Math @@ -16,8 +23,11 @@ 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 = interestRate/12; +// let periods = years*12; - +// console.log(monthlyInterestRate); +// console.log(peridos); // 🏡 Task 2: Harder Math /* Create your calculator! Use the formula in the ReadMe to run calculations on your numbers. Save the final value into a variable called monthlyRate. @@ -29,8 +39,17 @@ 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 power = (Math.pow((1 + monthlyInterestRate),periods)); +// // let topDivision = (monthlyInterestRate*power); +// // let bottomDivision = (power - 1); +// let monthlyRateFull = (principal*((monthlyInterestRate*power)/(power - 1))); +// let monthlyRate = monthlyRateFull.toFixed(2); - +// console.log(power); +// console.log(topDivision); +// console.log(bottomDivision); +// console.log(monthlyRateFull); +// console.log(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}" @@ -38,20 +57,24 @@ 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(name, monthlyRate){ + return name + ', your monthly rate is $' + monthlyRate; +} - - +// console.log(mortgageCalculator(name, monthlyRate)); // 🏡 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. For example, -mortgageCalculator(2000000, 0.05, 30); <-- should return 1,073.64 +mortgageCalculator(200000, 0.05, 30); <-- should return 1,073.64 */ +function mortgageCalculator(name, monthlyRate, principal, interestRate, years){ + return name + ', your monthly rate is $' + monthlyRate; +} - - +// console.log(mortgageCalculator(name, monthlyRate, 200000, 0.05, 30)); // 🏡 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). @@ -60,7 +83,35 @@ Then, add control flow within your function such that IF creditScore is above 74 */ - +function mortgageCalculator(creditScore){ + let principal = 200000; + let interestRate = 0.05; + let years = 30; + const name = 'Shanon'; + let monthlyInterestRate = interestRate/12; + let monthlyInterestRateBonus = (interestRate*0.995)/12; + let monthlyInterestRatePenalty = (interestRate*1.005)/12; + let periods = years*12; + // let power = (Math.pow((1 + monthlyInterestRate),periods)); + // let monthlyRateFull = (principal*((monthlyInterestRate*power)/(power - 1))); + // let monthlyRate = monthlyRateFull.toFixed(2); + + if (creditScore > 740){ + let power = (Math.pow((1 + monthlyInterestRateBonus),periods)); + let monthlyRateFull = (principal*((monthlyInterestRate*power)/(power - 1))); + let monthlyRate = monthlyRateFull.toFixed(2); + return name + ', your monthly rate is $' + monthlyRate; + } else if (creditScore < 660){ + let power = (Math.pow((1 + monthlyInterestRatePenalty),periods)); + let monthlyRateFull = (principal*((monthlyInterestRate*power)/(power - 1))); + let monthlyRate = monthlyRateFull.toFixed(2); + return name + ', your monthly rate is $' + monthlyRate; + } else { + return name + ', your monthly rate is $' + monthlyRate; + } +} + +console.log(mortgageCalculator(800)); // 🏡 Task 6: Loops /* Write a new function called variableInterestRate. This function should be the same as mortgageCalculator, except it should console.log the monthly payment for 10 different interest rates at 0.5% increments plus or minus 2% from the inputted interest rate. Complete these calculations using a for loop. From 692bfd07224be13f607fb2709056111828d56e10 Mon Sep 17 00:00:00 2001 From: shanon <13fritsh@gmail.com> Date: Wed, 13 May 2020 20:41:32 -0500 Subject: [PATCH 2/2] got task 6 to loop --- index.js | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 2ac02eb4..f573c85d 100644 --- a/index.js +++ b/index.js @@ -3,11 +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 principal = 200000; +let interestRate = 0.05; // let insterestRate = 0.05025; -// let years = 30; -// const name = 'Shanon'; +let years = 30; +const name = 'Shanon'; // console.log(principal); // console.log(insterestRate); @@ -23,8 +23,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. */ -// let monthlyInterestRate = interestRate/12; -// let periods = years*12; +let monthlyInterestRate = interestRate/12; +let periods = years*12; // console.log(monthlyInterestRate); // console.log(peridos); @@ -39,11 +39,11 @@ 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 power = (Math.pow((1 + monthlyInterestRate),periods)); +let power = (Math.pow((1 + monthlyInterestRate),periods)); // // let topDivision = (monthlyInterestRate*power); // // let bottomDivision = (power - 1); -// let monthlyRateFull = (principal*((monthlyInterestRate*power)/(power - 1))); -// let monthlyRate = monthlyRateFull.toFixed(2); +let monthlyRateFull = (principal*((monthlyInterestRate*power)/(power - 1))); +let monthlyRate = monthlyRateFull.toFixed(2); // console.log(power); // console.log(topDivision); @@ -111,7 +111,7 @@ function mortgageCalculator(creditScore){ } } -console.log(mortgageCalculator(800)); +// console.log(mortgageCalculator(800)); // 🏡 Task 6: Loops /* Write a new function called variableInterestRate. This function should be the same as mortgageCalculator, except it should console.log the monthly payment for 10 different interest rates at 0.5% increments plus or minus 2% from the inputted interest rate. Complete these calculations using a for loop. @@ -130,7 +130,13 @@ For example, variableInterestRate(200000, 0.04, 30) should console.log: */ +function variableInterestRate(name, interestRate, monthlyRate){ + for (i = 0; i < 5; i += 0.5){ + console.log(name + ", with and interest rate of " + i + ", your monthly rate is $" + monthlyRate); + } +} +console.log(variableInterestRate(name, 0.04, monthlyRate)) // 🌟🌟🌟 STRETCH 🌟🌟🌟//