Hi guys I am trying to solve this problem on JavaScript and I am stuck.
Instructions
This function takes a string of at least one character, and it should return the middle character(s) from that string.
If the string is of odd length, the function should return a single character. If the string is of even length, it should return the middle two characters concatenated together.
This is what I tried:
function returnMiddleCharacter(string) {
let letterCount = string.length;
let midChar = Math.round(letterCount/2)
if (letterCount === 1) {
return string;
}
if(letterCount % 2 !== 0){
return string[midChar]
}else{
string[midChar -1] + string[midChar]
}
}