I have been working on creating a word generator that prompts the user to input ten strings and then outputs a randomly selected one. However, instead of displaying the user input string, it is currently generating a random number. I am not encountering any errors but cannot figure out how to make it work correctly.
Does anyone have any suggestions or ideas on how I can modify this code to display the user input correctly?
I have been stuck on this issue for the past few days and would greatly appreciate your help.
function randomWordGenerator() {
// Define variables
var userInput = [];
var answer = [];
var range = 1;
// Prompt for Strings
for(var index = 0; index < 10; index++) {
userInput[index] = prompt("Please enter string " + (index + 1));
document.write("You entered: " + userInput[index] + "\n");
}
// Generate Random Number
for(var i = 0; i < range; i++) {
answer[i] = Math.floor((Math.random() * 10) + 1);
}
// Display Randomly Selected String
document.write("The generator chose: " + userInput[answer[0]-1]);
}
randomWordGenerator();