This is what I want.
User enters a numerical input. If he enters 2, the code prompts to enter two player names.
The player names are stored in an array. There is a 'next' button in the page, when user clicks it, the code prompts to enter another two names.
The next is the tricky part: Right now there are four names entered on two separate sessions. Now I need a nested array should hold the usernames in separate arrays based on the session.
I've tried many codes but only the following at least comes closer. But what happens is, every time user enters a new list of usernames, a new array is created but previous arrays are also over written.
var TotalNumOfPlayers = prompt("Enter The Total Number Of Players! (For example 2)");
var nameOfPlayers = [];
var loopThroughAllNames = new Array(new Array());
var NextList = document.querySelector("#NextList");
var tempArr = [];
addValue();
function addValue() {
for (var i = 0; i < TotalNumOfPlayers; i++) {
tempArr[i] = prompt("Enter Player name "+(i+1));
}
loopThroughAllNames.push(tempArr);
}
NextList.addEventListener("click", function() {
addValue();
});
<button id="NextList">Next list</button>