Sample Sequence Javascript Program 3 – BankSystem

Remember that he language being used throughout this tutorial is Javascript and because of this any time data is entered using the prompt command it is entered as characters. To turn the characters into numeric (floating point) data the parseFloat function is used, that is, Number = parseFloat(Number) ;

Sample Code

<html>
<head>
<script language='JavaScript'>
// Problem: BankSystem
// Constants and variables
const InterestRate = 2.5 ;

var Amount = 0.0 ;
var InterestDue = 0.0 ;

// Main Program
// Begin BankSystem

Amount = prompt ('Amount borrowed?') ;
Amount = parseFloat(Amount) ;

InterestDue = Amount * InterestRate / 100 ;

alert ('Interest due = ' + InterestDue.toFixed(2)) ;

// End BankSystem

</script>
<body>
</body>
</html>

Note: Adding .toFixed(2) to the variable InterestDue allows it to be displayed with two decimal places.

Next: Sequence Quiz