Sequence Javascript Program 1 – SquareSystem

The 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 rather than numbers. If this is not taken in account your programs may start to give what look like unusual output, for example in a program to add 10 to 20 the output given may be 1020 rather than 30. To turn the characters into numeric (integer) data the parseInt function is used, that is, Number = parseInt (Number) ;

Sample Code

<html>
<head>
<script language='JavaScript'>
// Problem: SquareSystem
// Variables
var Length = 0 ;
var Area = 0.0 ;

// Main Program
// Begin SquareSystem

Length = prompt ('Enter length: ') ;
Length = parseInt (Length) ;

Area = Length * Length ;

alert ('The area of the square is ' + Area) ;

// End SquareSystem

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

Next: Sequence Design 2 – AverageSystem