Math.abs() : abs : Math JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » Math » abs »

 

Math.abs()









Syntax








math.abs(num)



The abs() method is used to calculate the absolute value of num.












<html>
    <body>
    <script language="JavaScript">
    <!--
    function doMath(){
        var inputNum=document.form1.input.value;
        var result = Math.abs(inputNum);
        document.form1.answer.value = result;
    }
    -->
    </script>
    <form name=form1>
    This example calculates the absolute value of the number entered.
    <br><br>
    Enter Number:
    <input type="text" name="input" size=10>
    <input type="button" value="Calculate" onClick='doMath()'>
    <br>
    Answer:
    <input type="text" name="answer" size=10>
    </form>
    </body>
    </html>







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo Math
» abs