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 d8fd187 commit 5c3f09fCopy full SHA for 5c3f09f
Sprint-3/2-practice-tdd/count.js
@@ -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++;
+function countChar(str, char) {
+ let count = 0;
+
+ for (let i = 0; i < str.length; i++) {//loop through each character in the string
+ if (str[i] === char) {//check if the character matches the target character
6
+ count = count + 1;
7
}
8
- return count; // this replaces 'return 5'
9
-}
10
11
-module.exports = countChar;
+ return count;//return the final count
+}
12
+module.exports = countChar;
0 commit comments