var theOtherColor = "#FFCCFF";
function findHypotonuse(a,b){ # INPUTS: a,b
var c = Math.sqrt( a*a + b*b ); # Do some stuff.
document.bgColor = theOtherColor; # Side effect - do something else.
return c; # OUTPUT: return something
}
# .... other stuff here
var theAnswer = findHypotenuse(3, 4); # And here's how you use it.
<script language='JavaScript'>
function turnPageGreen(){
document.bgColor = "#00FF00";
}
</script>
<form name="pageGreenForm">
<input type="button" name="greenButton" value="Turn Page Green" onclick="turnPageGreen()">
</form>
<script language='JavaScript'>
function doubleIt(){
var x = parseFloat( document.doubleItForm.doubleItInput.value;
document.doubleItForm.doubleItInput.value = 2*x;
}
</script>
<form type="button" name="doubleItForm" id="doubleItID">
<input type="button" name="doubleItButton" value="Double this Number" onclick="doubleIt()">
<input type="input" name="doubleItInput" value="">
</form>