Free Puzzle Questions with Answer using Java, C#, JavaScript and PHP

JavaScript - Browser Detection

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <script language="JavaScript" type="text/javascript">
        function GetBrowserType(){
            var agent = navigator.userAgent;

            alert(agent);

            var chrome = agent.indexOf('Chrome');
            var ie = agent.indexOf('MSIE');
            var opera = agent.indexOf("Opera");
            var gecko = agent.indexOf("Gecko");
            var edge = agent.indexOf("Edge");

            if(edge != -1){
                alert("Current browser is EDGE");
            }
            else if(chrome != -1){
                alert("Current browser is CHROME");
            }
            else if(ie != -1){
                alert("Current browser is INTERNET EXPLORER");
            }
            else if(opera != -1){
                alert("Current browser is OPERA");
            }
            else if(gecko != -1){
                alert("Current browser is GECKO IE");
            }
            else{
                alert("Current browser is UNKNOWN");
            }

        }
    </script>
</head>
<body>
    <button onclick="GetBrowserType()">Show Browser Information</button>
</body>
</html>