Alright so I'm trying to make a program that prompts the user to enter a 4-6 words and then it displays them in reverse order.


here's the script i have so far for it:
<script type="text/javascript">
function ultraprompter5000(){

numberofwords=prompt("Enter a number 4-6 in the text field", "Enter number here");
if (numberofwords>6){
document.writeln("<p align=\"center\"> Number too large. Please refresh");
}
if (numberofwords<4){
document.writeln("<p align=\"center\"> Number too small. Please refresh");
}
else

for(i=0; i<numberofwords; i++){
word=prompt("Enter a word");
word[i]=word;

}
word[i]=word;

document.writeln("<p align=\"center\">"+word[5]);
document.writeln("<p align=\"center\">"+word[4]);
document.writeln("<p align=\"center\">"+word[3]);
document.writeln("<p align=\"center\">"+word[2]);
document.writeln("<p align=\"center\">"+word[1]);
document.writeln("<p align=\"center\">"+word[0]);

}
</script>

but that doesn't really work too great as it just displays each letter of the last word in reverse order. plus it leaves some blanks as undefined.

so is there some kind of array of strings that i can use to do this instead?

also it doesn't display the messages that i tell it to when the user enters a number less than or greater than the allowed amount. although it does notice and doesn't prompt the user for words.

any advice here on what i should do?
it actually doesn't even display all the letters. if i do six and the last word is six this is displayed:
"
undefined
undefined
undefined
i
x"
so its not displaying the first one for some reason