JavaScript – Nested If

Nested-if: Defining if block inside another if block. Inner block condition evaluates only when outer condition is valid.

Program to check the number is even or not only if it is positive.

<html>
            <head>
                        <script>
                                    function big()
                                    {
                                                var n = paseInt(document.getElementById(“num”).value);
                                                if(n>0){
                                                            if(n%2==0)
                                                                        document.write(“Even number”);
                                                            else
                                                                        document.write(“Odd number”);
                                                }
                                                else
                                                            document.write(“Input number is negative”);
                                    }
                        </script>
            </head>
            <body>
                        Enter Number : input type=”text” id=”num”/>br/>
                        <button onclick=”even()”> Even or Not </button>
            </body>
</html>
Scroll to Top