Returning in an if statement issue

I cant figure out why my if statements arent returning the value of result when the console.log(result) outputs just fine

function getMiddle(s) {
    let splittedS = s.split('')
    let odd = 0
    let even = 0
    let evenPlus1 = 2
    let result = ''
    let joined = ''
    if (splittedS.length % 2 == 1) {
        odd = Math.floor(splittedS.length / 2)
        joined = splittedS.join('')
        result = joined[odd]
        console.log(result);
        return result
    } else if (splittedS.length % 2 == 0) {
        even = splittedS.length / 2 - 1 // => 1 
        evenPlus1 = evenPlus1 + even // => 2
        joined = splittedS.join('') // => "dude"
        result = joined.substring(even, evenPlus1) // looks like string(1,3)
        console.log(result);
        return result
    }
}

getMiddle("dude")

You aren’t doing anything with the returned value from getMiddle. You are just calling the function and then letting the returned value vanish into thin air.

1 Like

ahhh, knew it was something dumb. thank you!