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 8f3d6cf commit 4b39af7Copy full SHA for 4b39af7
Sprint-3/2-practice-tdd/count.js
@@ -1,5 +1,23 @@
1
function countChar(stringOfCharacters, findCharacter) {
2
- return 5
+ if (typeof stringOfCharacters!= "string") {
3
+ throw new Error("Input should be a string");
4
+ }
5
+ if (typeof findCharacter !== "string" || findCharacter.length != 1){
6
+ throw new Error ("Input must be a single character");
7
8
+
9
+ let count = 0;
10
+ for(let char of stringOfCharacters) {
11
+ if (char === findCharacter) {
12
+ count++;
13
14
15
+ return count;
16
17
}
18
19
module.exports = countChar;
20
21
+console.log(countChar("amazon", "a"));
22
23
+// Added lines to check cases and return count of characters.
0 commit comments