Counter

Counts the number of each corresponding set

by Marcus Baptiste

HTML

<textarea id="words"></textarea>
<br>
<button id="btncalc" onclick="calc();">Calculate</button>

JavaScript

$(document).ready(function () {
    $("#btncalc").click(function () {
        var testtext = $(this).siblings("#words").val(),
        var km = 0,
            oq = 0,
            eg = 0,
            testchar = 0;

        for (i = 0; i < testtext.length; i++) {
            testchar = testtext.charCodeAt(i);
            switch (testchar) {
                case 107:
                case 108:
                case 109:
                    km++;
                    break;
                case 111:
                case 112:
                case 113:
                    oq++;
                    break;
                case 101:
                case 102:
                case 103:
                    eg++;
                    break;
            }
        }

        alert("number of: \n " +
            "k - m = " + km +
            "\n o - q = " + oq +
            "\n e - g = " + eg);

    });
});