-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExOh.js
More file actions
41 lines (34 loc) · 917 Bytes
/
ExOh.js
File metadata and controls
41 lines (34 loc) · 917 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* Using the JavaScript language, have the function ExOh(str)
take the str parameter being passed and return the string true
if there is an equal number of x's and o's, otherwise return
the string false. Only these two letters will be entered in
the string, no punctuation or numbers.
For example: if str
is "xooxxxxooxo" then the output should return false because
there are 6 x's and 5 o's. */
function ExOh(str) {
var countX = 0;
var countO = 0;
var isEven = false;
var strArray = str.split('');
console.log(strArray);
for(i = 0; i < strArray.length; i++){
var testSpace = strArray[i];
console.log(testSpace);
if (/^[xX]/.test(testSpace)){
countX++;
} else if (/^[oO]/.test(testSpace)){
countO++;
} else {
continue;
}
}
console.log(countX);
console.log(countO);
if (countX === countO) {
isEven = true;
}
return isEven;
}
//ExOh('xoxoxoxo');
ExOh('x');