Example JavaScript Program

<html>
<head>
<script type='text/javascript'>

// Variables
var ActualMark = 0 ;
var PossibleMark = 0 ;
var PercentageMark = 0.0 ;

// Main Program
ActualMark = prompt ('Please type the students actual mark: ') ;
PossibleMark = prompt ('Please type the total possible mark of the exam : ') ;

PercentageMark = (ActualMark / PossibleMark) * 100 ;

if (PercentageMark >= 50)
{ // Begin if
alert (PercentageMark + '%' + ' ' + 'is a Pass') ;
} // End if
else
{ // Begin else
alert (PercentageMark + '%' + ' ' + 'is a Fail') ;
} // End else }

</script>
</head>
<body>

</body>
</html>

This program shows an example of a binary selection where there are only two cases :

ActualMark >= 50 or ActualMark < 50

Next: Compound Statements