JavaScript – If Else If

If-else-if ladder: 

  • It is allowed to defined multiple if blocks sequentially.
  • Itexecutes only one block among the multiple blocks defined.

Program to check biggest among two numbers:

<html>
            <head>
                        <script>
                                    function big(){
                                                var a = parseInt(document.getElementById(“first”).value);
                                                var b = parseInt(document.getElementById(“second”).value);
                                                var c = parseInt(document.getElementById(“third”).value);
                                                if(a>b && a>c)
                                                            document.write(“a is big”);
                                                if(b>c)
                                                            document.write(“b is big”);
                                                else
                                                            document.write(“c is big”);
                                    }
                        </script>
            </head>
            <body>
                        First Number : <input type=”text” id=”first”/>br/>
                        Second Number : <input type=”text” id=”second”/><br/>
                        Third Number : <input type=”text” id=”third”/>br/>
                        <button onclick=”big()”> Biggest of 3 </button>
            </body>
</html>
Scroll to Top