Find the middle 2 letter of an even word in the middle word of a sentence or

find the middle letter of an odd word in the middle of the middle word of a sentence. my code just returns undefined not sure why. is there a better method?

 if (string.length%2===1){
 const newArray = string.split(" ")
    const middleWord = newArray[(newArray.length+1)/2];
    if (middleWord.length%2===1){
      return middleWord[(middleWord.length+1)/2];
    else {
        const firstmiddleletter = middleWord[middleWord.length/2];
      const secondmiddleletter = middleWord[(middleWord.length/2)+1];
      const middletwo = `${firstmiddleletter}${secondmiddleletter}`;
      return middletwo;
    return 1;
 // console.log(middleWord)

const stringy = "I want to see the middle letter of the middle word";

could you please give all your code? It seems the function definition is missing and makes debugging difficult

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.