function countBs(s) {
    let count = 0;
    for (let i = 0; i < s.length; ++i) {
        if (s[i] == "B") ++count;
    }
    return count;
}

function countChar(s, c) {
    let count = 0;
    for (let i = 0; i < s.length; ++i) {
        if (s[i] == c) ++count;
    }
    return count;
}

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

function countChar(s, c) {
	let count = 0;
	for (let i = 0; i < s.length; ++i) {
		if (s[i] == c) ++count;
	}

	return count;
}

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

Add chapter 3, exercise 3
Add chapter 3, exercise 3
