Skip to content

Commit 5c3f09f

Browse files
committed
Updated the CountChar function
1 parent d8fd187 commit 5c3f09f

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

Sprint-3/2-practice-tdd/count.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
function countChar(stringOfCharacters, findCharacter) {
2-
let count = 0;
3-
for (let i = 0; i < stringOfCharacters.length; i++) {
4-
if (stringOfCharacters[i] === findCharacter) {
5-
count++;
1+
function countChar(str, char) {
2+
let count = 0;
3+
4+
for (let i = 0; i < str.length; i++) {//loop through each character in the string
5+
if (str[i] === char) {//check if the character matches the target character
6+
count = count + 1;
67
}
78
}
8-
return count; // this replaces 'return 5'
9-
}
109

11-
module.exports = countChar;
10+
return count;//return the final count
11+
}
12+
module.exports = countChar;

0 commit comments

Comments
 (0)