mirror of
https://git.hackliberty.org/Awesome-Mirrors/OSSU-computer-science.git
synced 2024-08-20 14:08:53 -06:00
Intro to CS - problem set 01.01 - finish problem set 01.01
This commit is contained in:
parent
2cd2e03d49
commit
c8587050fa
@ -42,23 +42,30 @@ prompt.get([
|
|||||||
}
|
}
|
||||||
], function( err, results ) {
|
], function( err, results ) {
|
||||||
|
|
||||||
|
console.log( results );
|
||||||
|
|
||||||
// constants
|
// constants
|
||||||
var PERIOD = 12;
|
var PERIOD = 12;
|
||||||
|
|
||||||
// input variables
|
// input variables
|
||||||
var initialBalance = parseInt( results.balance, 10 );
|
var initialBalance = parseFloat( results.balance, 10 );
|
||||||
var interest = parseInt( results.interest, 10 );
|
var interest = parseFloat( results.interest, 10 );
|
||||||
var minPayment = parseInt( results.minimum, 10 );
|
var minPayment = parseFloat( results.minimum, 10 );
|
||||||
|
|
||||||
|
console.log( initialBalance );
|
||||||
|
console.log( interest );
|
||||||
|
console.log( minPayment );
|
||||||
|
|
||||||
// output variables
|
// output variables
|
||||||
var month = 1;
|
var month = 1;
|
||||||
var minMonthlyPayment = 0;
|
var minMonthlyPayment = 0;
|
||||||
var principalPaid = 0;
|
var principalPaid = 0;
|
||||||
var actualBalance = 0;
|
var actualBalance = initialBalance;
|
||||||
|
|
||||||
// helper variables
|
// helper variables
|
||||||
var actualMinPayment;
|
var actualMinPayment = 0;
|
||||||
var actualInterest;
|
var actualInterest = 0;
|
||||||
|
var totalPaid = 0;
|
||||||
|
|
||||||
while( month <= PERIOD ) {
|
while( month <= PERIOD ) {
|
||||||
|
|
||||||
@ -66,14 +73,19 @@ prompt.get([
|
|||||||
actualInterest = ( interest / 12 ) * actualBalance;
|
actualInterest = ( interest / 12 ) * actualBalance;
|
||||||
principalPaid = actualMinPayment - actualInterest;
|
principalPaid = actualMinPayment - actualInterest;
|
||||||
actualBalance -= principalPaid;
|
actualBalance -= principalPaid;
|
||||||
|
totalPaid += actualMinPayment;
|
||||||
|
|
||||||
console.log( 'Month:', month );
|
console.log( 'Month:', month );
|
||||||
console.log( 'Minimum monthly payment:', actualMinPayment );
|
console.log( 'Minimum monthly payment:', actualMinPayment.toFixed( 2 ));
|
||||||
console.log( 'Principal paid:', principalPaid );
|
console.log( 'Principal paid:', principalPaid.toFixed( 2 ));
|
||||||
console.log( 'Remaining balance', actualBalance, '\n' );
|
console.log( 'Remaining balance', actualBalance.toFixed( 2 ), '\n' );
|
||||||
|
|
||||||
month += 1;
|
month += 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log( '======= RESULT =======');
|
||||||
|
console.log( 'Total amount paid:', totalPaid.toFixed( 2 ));
|
||||||
|
console.log( 'Remaining balance', actualBalance.toFixed( 2 ), '\n' );
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user