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];
}
console.log(middleWord[(middleWord.length+1)/2])
else {
const firstmiddleletter = middleWord[middleWord.length/2];
const secondmiddleletter = middleWord[(middleWord.length/2)+1];
const middletwo = `${firstmiddleletter}${secondmiddleletter}`;
console.log(middletwo)
return middletwo;
}
return 1;
}
// console.log(middleWord)
}
const stringy = "I want to see the middle letter of the middle word";
//console.log((middle(stringy)))