Tuesday, 19 November 2013

Logical Pattern Question using JavaScript:

Like

s=2
u=1
b=1
a=1
s=2

Ans:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>

    <script>
        function CallMe() {
            var num = document.getElementById("txtString").value;
            var count = 0;
            for (var i = 0; i <= num.length - 1; i++) {

                count = 0;
                for (var j = 0; j <= num.length - 1; j++) {
                    if (num[i] == num[j]) {
                        count++;
                    }

                }

                document.write(num[i] + "=" + count + "<br/>");
            }
        }
                alert("hi")

    </script>
</head>
<body>
    <input id="txtString" type="text" placeholder="Enter Any String.."/>
    <input id="btnSubmit" type="button" value="button" onclick="CallMe()" />
</body>
</html>

No comments:

Post a Comment