I hope everyone is having a good day.
This is my first ever post on Stackoverflow!
I have just completed the javascript course on codeacademy and have read a couple of books on it too. Now I am on codewars. I would classify myself as a beginner in Javascript.
I find myslef a little stuck on a challenge, please can someone shed some light on what I may be doing wrong? Many thanks in advance!
Here is the instructions:
Check to see if a string has the same amount of 'x's and 'o's. The method must return a boolean and be case insensitive. The string can contains any char.
And here is my code:
function XO(str) {
var x = [];
var o = [];
for (var i = 0; i <= str.length; i++) {
if (str(i).toLowerCase === "x") {
x.push(i);
} else if (str(i).toLowerCase === "o") {
o.push(i);
}
if (x.length === o.length) {
return true;
} else {
return false;
}
}
}