Ad

Return the middle character of the string. If the string's length is odd, return the middle character. If the string's length is even, return the middle 2 characters.

function middleCharacter(str) {
 if (str.length % 2 !== 0) {
  return str.slice(str.length/2, str.length/2+1);
};
  return str.slice(str.length/2-1, str.length/2+1);
};