|
2 | 2 | Lab Start */ |
3 | 3 |
|
4 | 4 | /* TODO Create a the Loans namespace. */ |
5 | | - |
6 | | - |
7 | | -interface Loan { |
8 | | - principle: number, |
9 | | - interestRate: number //* Interest rate percentage (eg. 14 is 14%) |
10 | | -} |
11 | | -interface ConventionalLoan extends Loan { |
12 | | - months: number //* Total number of months |
| 5 | +namespace Loans { |
| 6 | + export interface Loan { |
| 7 | + principle: number; |
| 8 | + interestRate: number; //* Interest rate percentage (eg. 14 is 14%) |
| 9 | + } |
| 10 | + export interface ConventionalLoan extends Loan { |
| 11 | + months: number; //* Total number of months |
| 12 | + } |
13 | 13 | } |
14 | 14 |
|
15 | 15 | /* TODO Create LoanPrograms namespace. */ |
16 | | - |
17 | | - |
18 | | -/* TODO Update the calculateInterestOnlyLoanPayment function. */ |
19 | | -function calculateInterestOnlyLoanPayment(loanTerms: Loan): string { |
| 16 | +namespace LoanPrograms { |
| 17 | + /* TODO Update the calculateInterestOnlyLoanPayment function. */ |
| 18 | + export function calculateInterestOnlyLoanPayment(loanTerms: Loans.Loan): string { |
20 | 19 | let payment: number; |
21 | 20 | payment = loanTerms.principle * calculateInterestRate(loanTerms.interestRate); |
22 | | - return 'The interest only loan payment is ' + payment.toFixed(2); |
23 | | -} |
24 | | -/* TODO Update the calculateConventionalLoanPayment function. */ |
25 | | -function calculateConventionalLoanPayment(loanTerms: ConventionalLoan): string { |
| 21 | + return "The interest only loan payment is " + payment.toFixed(2); |
| 22 | + } |
| 23 | + /* TODO Update the calculateConventionalLoanPayment function. */ |
| 24 | + export function calculateConventionalLoanPayment(loanTerms: Loans.ConventionalLoan): string { |
26 | 25 | let interest: number = calculateInterestRate(loanTerms.interestRate); |
27 | 26 | let payment: number; |
28 | | - payment = loanTerms.principle * interest / (1 - (Math.pow(1/(1 + interest), loanTerms.months))); |
29 | | - return 'The conventional loan payment is ' + payment.toFixed(2); |
30 | | -} |
31 | | -function calculateInterestRate (interestRate: number): number { |
| 27 | + payment = |
| 28 | + (loanTerms.principle * interest) / |
| 29 | + (1 - Math.pow(1 / (1 + interest), loanTerms.months)); |
| 30 | + return "The conventional loan payment is " + payment.toFixed(2); |
| 31 | + } |
| 32 | + function calculateInterestRate(interestRate: number): number { |
32 | 33 | let interest: number = interestRate / 1200; |
33 | | - return interest |
| 34 | + return interest; |
| 35 | + } |
34 | 36 | } |
35 | 37 |
|
36 | 38 | /* TODO Add reference paths. */ |
37 | 39 |
|
38 | 40 | /* TODO Update the function calls. */ |
39 | 41 |
|
40 | | -let interestOnlyPayment = calculateInterestOnlyLoanPayment({principle: 30000, interestRate: 5}); |
41 | | -let conventionalLoanPayment = calculateConventionalLoanPayment({principle: 30000, interestRate: 5, months: 180}); |
42 | | -console.log(interestOnlyPayment); //* Returns "The interest only loan payment is 125.00" |
43 | | -console.log(conventionalLoanPayment); //* Returns "The conventional loan payment is 237.24" |
| 42 | +let interestOnlyPayment = LoanPrograms.calculateInterestOnlyLoanPayment({ |
| 43 | + principle: 30000, |
| 44 | + interestRate: 5, |
| 45 | +}); |
| 46 | +let conventionalLoanPayment = LoanPrograms.calculateConventionalLoanPayment({ |
| 47 | + principle: 30000, |
| 48 | + interestRate: 5, |
| 49 | + months: 180, |
| 50 | +}); |
| 51 | +console.log(interestOnlyPayment); //* Returns "The interest only loan payment is 125.00" |
| 52 | +console.log(conventionalLoanPayment); //* Returns "The conventional loan payment is 237.24" |
0 commit comments