I have created javascript function to display array items when index values are entered in input box but it is not working but i want to do it through forloop
<html>
<head>
<title>ForLoop</title>
</head>
<body>
<input id="answer"/><br/><br/>
<button id="btn">Generate</button><br/><br/>
<h1 id="ans"></h1>
<script>
var MyArray=["Lion","Mouse","Cat","Dog","Buffalo","Cow","Rat","Tiger","Monkey","Lepoard","Lizard"]
for(var i=0; i<MyArray.length;i++){
document.getElementById("btn").onclick=function(){
if( document.getElementById("answer").value==MyArray[i]){
document.getElementById("ans").innerHTML=MyArray[i]
}
}
}
</script>
</body>
</html>