In Association with Amazon.in   Flipkart

Monday, September 30, 2013

JavaScript Function With Both Arguments And Rreturn Type

<head>
<script>
// Function With both Arguments and return type
    function clac(x, s, y)  //  called function
    {
        switch(s)
        {
        case '+': return(x+y); break;
        case '-': return(x-y); break;
        case '*': return(x*y); break;
        case '/': return(x/y); break;
        case '%': return(x%y); break;
           
        }
    }
</script>
</head>
<body>
    <script>
    line1(); 
    res=clac(5, '*', 80);   //  calling function
    document.write("<br/>Res="+ res);
    line('$', 50);
    document.write("<br/>ANs=" + clac(52, '/', 3));
    </script>
</body>


output:

 Res=400
ANs=17.333333333333332


No comments:

Post a Comment


Related Posts Plugin for WordPress, Blogger...