Sequence Javascript Program 2 – AverageSystem

When working with numeric data input always remember to use parseInt (Integers) and parseFloat (Real numbers) to change from characters to numbers.

Sample Code

<html>
<head>
<script language='JavaScript'>
// Problem: AverageSystem
// Variables

var Num1 = 0 ;
var Num2 = 0 ;
var Sum = 0.0 ;
var Average = 0.0 ;

// Main Program
// Begin AverageSystem

Num1 = prompt ('Enter number 1: ') ;
Num1 = parseInt (Num1) ;

Num2 = prompt ('Enter number 2: ') ;
Num2 = parseInt (Num2) ;

Sum = Num1 + Num2 ;
Average = Sum / 2 ;

alert ('Average = ' + Average) ;

// End AverageSystem

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

Next: Sequence Design 3 – BankSystem