Finding the absolute value : Conditional Operator : Operators JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » Operators » Conditional Operator »

 

Finding the absolute value

















<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>







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo Operators
» Conditional Operator