<html>
<head>
<title>Finding the absolute value</title>
<script language="javascript" type="text/javascript">
<!--
function f()
{
var myVar = prompt("A number", "");
var theModulus = (myVar>=0)? myVar: -myVar;
var msg = (isNaN(theModulus))? "Numbers only.": "The modulus of " + myVar + " is " + theModulus;
alert(msg);
}
//-->
</script>
</head>
<body>
<h1>Finding the absolute value</h1>
<a href="javascript:f()">Get absolute value</a>
</body>
</html>
|