Skip to content
Permalink
5d28269657
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
31 lines (28 sloc) 945 Bytes
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Week 5 Exercise: 3</title>
</head>
<body>
<h1><code>Bean Counting Exercise</code></h1>
<script>
//Exercise 3
console.log("Exercise 3: Bean Counting")
function countChar (string, char) { //function taking in two arguements
let counted = 0;
for (let i = 0; i < string.length; i++) {
if (string[i] == char) { //if current character equals (char)
counted += 1; //add 1 to counter variable
}
}
return counted;
}
function countBs(string) { //function taking one arguement as string
return countChar(string, "B");
}
</script>
</body>
</html>