<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en"><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Mozilla/4.75C-CCK-MCD {C-UDP; EBM-APPLE} (Macintosh; U; PPC) [Netscape]">
<style type="text/css">
.style1 {
text-align: center;
}
<title>Excersise 11</title>
</style>
</head><body text="#330066" bgcolor="#ffffff" link="#3300cc" vlink="#330066" alink="#33ff33">
<center>
<h2>
<font color="#1717ff"><font size="+3">Practical exercise eleven.</font></font></h2></center>
<center>
<h2>
<font color="#1717ff"><font size="+3">Simple if then else example.</font></font></h2></center>
<p><br><font size="+2">This script illustrates the use of a binary decision
control structure.</font>
<br><font face="Courier New,Courier"><font color="#230fff"><font size="+1">function
test(theparam)</font></font></font>
<br><font face="Courier New,Courier"><font color="#230fff"><font size="+1"> {
<br>
if (theparam >= 50)</font></font></font>
<br><font face="Courier New,Courier"><font color="#230fff"><font size="+1"> {document.form1.Outputwindow.value
=" you got a pass"</font></font></font>
<font face="Courier New,Courier"><font color="#230fff"><font size="+1">}</font></font></font>
<br><font face="Courier New,Courier"><font color="#230fff"><font size="+1"> else</font></font></font>
<br><font face="Courier New,Courier"><font color="#230fff"><font size="+1"> {</font></font></font>
<font face="Courier New,Courier"><font color="#230fff"><font size="+1"><br>
alert("The
result was a fail","")</font></font></font><br><font face="Courier New,Courier"><font color="#230fff"><font size="+1"> document.form1.Outputwindow.value
=" you need " + ( 50 -theparam) + <br>
" more marks"</font></font></font>
<br><font face="Courier New,Courier"><font color="#230fff"><font size="+1"> }//
end of the decision</font></font></font>
<br><font face="Courier New,Courier"><font color="#230fff"><font size="+1"> }//
end of the function</font></font></font>
</p><p><font size="+2">Q1. Copy and modify the script to produce a result of
"Credit " for marks over 75 and "pass" for marks between 50 and 75 inclusive.<br>
</font></p>
<p><font size="+2">result < 50 -->fail<br>
result >= 50 & result <=75 --> pass<br>
result >75 credit<br>
<br>
</font>
</p>
<p><script>
<!-- Beginning of JavaScript
function test(theparam)
{ if (theparam >= 50)
{document.form1.Outputwindow.value =" You got a Pass"
}
else
{
alert("The result was a fail","")
document.form1.Outputwindow.value =" You need " + ( 50 -theparam) + " more marks"
}
{ if (theparam >75 && <99)
{document.form1.Outputwindow.value =" You got a Credit"
}
}// end of the decision
}// end of the function
// - End of JavaScript - -->
</script>
</p><form name="form1">
<div class="style1">
<textarea name="Outputwindow" cols="60" style="height: 55px"></textarea>
<br><br>
Type a test mark here: <input size="10" name="parameter_holder" type="text">
<br>
<br>
Check the test mark to see if its a pass. <br>
<br>
<input type="button" value="What is the Result?" onclick="test(document.form1.parameter_holder.value)" name="Button" style="width: 131px">
<hr></div>
</form>
<br>
<br>
</body></html>