Intro to CS - problem set 01.01 - set all variables

pull/357/head
Eric Douglas 2015-06-20 18:43:37 -03:00
parent 18d4dbdf3d
commit 2cd2e03d49
1 changed files with 19 additions and 10 deletions

View File

@ -30,15 +30,15 @@ prompt.start();
prompt.get([ prompt.get([
{ {
name : 'balance', name : 'balance',
description : 'Outstanding balance' description : 'Enter the outstanding balance on your credit card'
}, },
{ {
name : 'interest', name : 'interest',
description : 'Annual interest rate' description : 'Enter the annual credit card interest rate as a decimal'
}, },
{ {
name : 'minimum', name : 'minimum',
description : 'Minimum monthly payment rate' description : 'Enter the minimum monthly payment rate as a decimal'
} }
], function( err, results ) { ], function( err, results ) {
@ -46,9 +46,9 @@ prompt.get([
var PERIOD = 12; var PERIOD = 12;
// input variables // input variables
var initialBalance = results.balance; var initialBalance = parseInt( results.balance, 10 );
var interest = results.interest; var interest = parseInt( results.interest, 10 );
var minPayment = results.minimum; var minPayment = parseInt( results.minimum, 10 );
// output variables // output variables
var month = 1; var month = 1;
@ -56,14 +56,23 @@ prompt.get([
var principalPaid = 0; var principalPaid = 0;
var actualBalance = 0; var actualBalance = 0;
while( month < PERIOD ) { // helper variables
var actualMinPayment;
var actualInterest;
let actualMinPayment = minPayment * actualBalance; while( month <= PERIOD ) {
let actualInterest = ( interest / 12 ) * actualBalance;
actualMinPayment = minPayment * actualBalance;
actualInterest = ( interest / 12 ) * actualBalance;
principalPaid = actualMinPayment - actualInterest;
actualBalance -= principalPaid;
console.log( 'Month:', month ); console.log( 'Month:', month );
console.log( 'Minimum monthly payment:', actualMinPayment ); console.log( 'Minimum monthly payment:', actualMinPayment );
console.log( 'Principal paid:', ); console.log( 'Principal paid:', principalPaid );
console.log( 'Remaining balance', actualBalance, '\n' );
month += 1;
} }