mirror of
https://git.hackliberty.org/Awesome-Mirrors/OSSU-computer-science.git
synced 2024-08-21 06:29:00 -06:00
Intro to CS - v01 problem set 01.02
This commit is contained in:
parent
0e83b4bad5
commit
7fd8bfba45
@ -33,20 +33,22 @@ prompt.get([
|
|||||||
var interest = parseFloat( results.interest );
|
var interest = parseFloat( results.interest );
|
||||||
|
|
||||||
// helper variables
|
// helper variables
|
||||||
var monthPayment = 0;
|
|
||||||
var monthsNeeded = 0;
|
var monthsNeeded = 0;
|
||||||
var totalBalance = initialBalance;
|
var totalBalance = initialBalance;
|
||||||
var monthInterest = interest / 12;
|
var monthInterest = interest / 12;
|
||||||
|
var monthPayment = Math.ceil( initialBalance * ( 1 + interest ) / 120 ) * 10;
|
||||||
|
// (( balance * ( interest ) / 12 ) / 10 ) * 10
|
||||||
|
|
||||||
while ( totalBalance > 0 ) {
|
while ( totalBalance > 0 ) {
|
||||||
|
|
||||||
|
totalBalance = ( totalBalance * ( 1 + monthInterest ) - monthPayment ).toFixed( 2 );
|
||||||
|
monthsNeeded += 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log( '======= RESULT =======');
|
console.log( '======= RESULT =======');
|
||||||
console.log( 'Monthly payment to pay off debt in 1 year:' );
|
console.log( 'Monthly payment to pay off debt in 1 year:', monthPayment );
|
||||||
console.log( 'Number of months needed:' );
|
console.log( 'Number of months needed:', monthsNeeded );
|
||||||
console.log( 'Balance' );
|
console.log( 'Balance', totalBalance );
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user