Recently, I've been delving into JavaScript and exploring the functionality of the 'for' statement. However, I have a question that's been on my mind. I've managed to use the 'for' statement to produce output, like this:
for (i = 0; i < 3; i++) {
console.log(i);
}
But what about assigning a variable to capture the entire output of the 'for' statement?
var destinationArray = ["town", "areas", "bosses"];
var destinationArraySet = 1;
var i;
for (i = 0; i < destinationArraySet; i++) {
console.log(destinationArray[i]);
} /* This should be equivalent to var destination */
var userDestinationPrompt = ("Where would you like to go? Available places: " +
/* var destination */
+
".").toUpperCase();
Just to provide some additional context: I'm working on a game where new destinations become available as previous ones are cleared. When this happens, I increase the value of destinationArraySet, resulting in more places being displayed after 'Available places'.
Any help or clarification is greatly appreciated! Feel free to ask if anything seems unclear.