We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent dbf085f commit a09a992Copy full SHA for a09a992
Sprint-3/2-practice-tdd/count.js
@@ -1,5 +1,18 @@
1
function countChar(stringOfCharacters, findCharacter) {
2
- return 5
+ // start a count of 0
3
+ let count = 0;
4
+
5
+ // check each of the characters in the string one by one.
6
+ for (let i = 0; i < stringOfCharacters.length; i++) {
7
+ // checks if the current characters matches the one were looking for in the string.
8
+ if (stringOfCharacters[i] === findCharacter)
9
+ // if it does, we increment the count by 1.
10
+ count = count + 1;
11
+}
12
13
+ return count;
14
}
15
+console.log(countChar("aaaaa", "a")); // 5
16
+console.log(countChar("hello", "l")); // 2
17
-module.exports = countChar;
18
+module.exports = countChar;
0 commit comments