Exes and Ohs

JavaScript

function XO(str) {
  let numX = 0, numO = 0;
  str = str.toLowerCase();
  for (let i = 0; i < str.length; i++) {
    if (str[i] == 'x') {
      numX++;
    } else if (str[i] == 'o') {
      numO++;
    }
  }

  return numX == numO;
}

Tags

  1. javascript (Private)
  2. 7-kyu (Private)
  3. codewars (Private)
  4. answer (Private)