Extracting middle of string - JavaScript
<p>I am trying to write an algorithm for this in JavaScript but I am getting a str.length is not a function...</p>

<pre><code>function extractMiddle(str) {

    var position;
    var length;

    if(str.length() % 2 == 1) {
        position = str.length() / 2;
        length = 1;
    } else {
        position = str.length() / 2 - 1;
        length = 2;
    }

    result = str.substring(position, position + length)

}

extractMiddle("handbananna");
</code></pre>