Hi, I am new here and I was wondering if anyone here could point me in the right direction.
We are supposed to do a simple hangman game.
The exercise is about uploading a .txt file with words separated by a space and converting those words into an array. Then the program asks the user what is the number of the word the user wants to try to guess.
Up to this point there is no problem, but once I try to execute the "fu" function, nothing happens.

The "fu" function is supposed to reveal the first and last letters of the word and also accomodate a guessing letter into the "theWord" form if it matches the word chosen by the user.

Any thoughts on how to make this work are appreciated.


<html>

<head>

<title>Hangman 2.0</title>
<input type="file" id="fileinput" />
<script type="text/javascript">

var i=0;

function readSingleFile(evt) {

var f = evt.target.files[0];


if (f) {
var r = new FileReader();
r.onload = function(e) {
var contents = e.target.result; // almacena contenido
alert("Succesful data load ");
lista=contents.split(" ");//sirve para separar los contenidos del archivo por espacios y acomodarlos en el array
var num=prompt("Hay "+lista.length+" palabras, cual es el número de la palabra que quieres adivinar ?");
var palabra=lista[num].split("");





}

r.readAsText(f);

}

}
document.getElementById('fileinput').addEventListener('change', readSingleFile, false);

function fu(){
i=0;
var letra=document.theWord.guess.value;

document.theWord[0].value=palabra[0];
document.theWord[palabra.length-1].value=palabra[palabra.length-1];


for (i=0 ;i<palabra.length ;i++ ){
if (letra==palabra[i]){
document.theWord[i].value=letra;
}
}
}


</script>

</head>

<body>
<form name="theWord" id="theWord">
<br><br>
<script language="javascript" type="text/javascript">
var cont=0;
for (cont=0 ;cont<14 ;cont++ ) {
document.write("<input type=text size=4 readonly=true>");
}
</script>
<br><br>
<u><font color="black" size="1" face="Verdana">Insert your Letter here</font></u>
<input type="text" name="guess" size="5">

<input name="try" id="try" type="button" value="Try" onclick="fu()">

</form>
</body>

</html>