[
// Define the variables
var stringIn = [];
var finalMessage = "Thanks for participating!";
// Get input from user
stringIn[0] = prompt("Enter the first string:");
stringIn[1] = prompt("Enter the second string:");
stringIn[2] = prompt("Enter the third string:");
stringIn[3] = prompt("Enter the fourth string:");
stringIn[4] = prompt("Enter the fifth string:");
// For loop and display
for(var myCounter = 0; myCounter < 5; myCounter++) {
document.write("You entered: " + stringIn + "\n");
}
document.write("\n" + finalMessage);
My output should be: You entered: Alpha You entered: Bravo You entered: Charlie You entered: Delta You entered: Echo
but I'm getting:
You entered: Alpha,Bravo,Charlie,Delta,Echo You entered: Alpha,Bravo,Charlie,Delta,Echo You entered: Alpha,Bravo,Charlie,Delta,Echo You entered: Alpha,Bravo,Charlie,Delta,Echo You entered: Alpha,Bravo,Charlie,Delta,Echo
I've added my code to help with my problem. FireFox Web Console shows no errors and if I had an error, I wouldn't have any output. What is wrong with this code?
+ stringIn +, how's it supposed to know which element ofstringInto use? Hence, writestringIn[myCounter]to access the element at indexmyCounter