function countBs(string) {
    return countChar(string, "B");
}

function countChar(string, ch) {
    var counted = 0;
    for (var i = 0; i < string.length; i++) {
        if (string.charAt(i) == ch)
            counted += 1;
    }
    return counted;
}

console.log(countBs("BBC"));
// -> 2
console.log(countChar("kakkerlak", "k"));
// -> 4
