Change this line:
document.getElementById("name").innerHTML = arry[0].random;
to this:
document.getElementById("name").innerHTML = randomName();
Working demo: http://jsbin.com/xugeg/1
You created the function randomName()
to fetch a random value from your array and all you need to do is to call it.
arry[0].random;
is wrong because arry[0]
is a string and does not have a property named random
.