Skip to content
Permalink
708762f8c6
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
32 lines (26 sloc) 548 Bytes
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bean Counting</title>
</head>
<body>
<script>
function countBs(string) {
return countChar(string, 'B');
}
function countChar(string, chr) {
var counter = 0
for (var i = 0; i < string.length; i++) {
if (string.charAt(i) === chr) {counter++;}
}
return counter;
}
console.log(countBs("BBC"));
// → 2
console.log(countChar("kakkerlak", "k"));
// → 4
</script>
</body>
</html>