Undefined in associative array lookup
<pre><code>var candidates = {           
  "1":"Barack Obama",
  "2":"Mitt Romney",
  "3":"Dennis Kucinich",
  "4":"Quentin Tarantino",
  "5":"Count Dracula"
};



    function getRandomInt(min, max){
return Math.floor(Math.random() * (max - min + 1)) + min;
}

Object.size = function(obj) {
    var size = 0, key;
    for (key in obj) {
        if (obj.hasOwnProperty(key)) size++;
    }
    return size;
};

function getRandomPresident(){
  var num = getRandomInt(1, Object.size(candidates));
  if (num!=5){

    alert(num);
    var key = num.toString();
    var res = candidates[key];

    return res;



  } else {

        getRandomPresident();

  }

   }


 alert(getRandomPresident());
</code></pre>

<p>This code works, but sometimes after generating random value it outputs "undefined" instead of the name - <a href="http://jsbin.com/uriwal/edit#source" rel="nofollow">http://jsbin.com/uriwal/edit#source</a>    Why?</p>
