I have the following code that randomly generates an alphanumeric string:
var currentGameID = Math.random().toString(36).slice(2);
Then, in the following code, take the names of the players from the text boxes and store them in a new object, staying as follows:
$(document).ready(function() {
$("#newGame").click(function() {
player1Name = $("#jugador1").val();
player2Name = $("#jugador2").val();
gamesSessions = {
sessionID: {
gameID: {
player1Name: player1Name,
player2Name: player2Name
}
}
};
});
});
What I need to know is how I can make the variable "currentGameID" be the array that contains "player1Name" and "player2Name", so that it could save the player data inside each "currentGameID" .
The complete code is as follows:
var currentGameID = Math.random().toString(36).slice(2);
console.log(currentGameID);
var player1Name;
var player2Name;
var gamesSessions;
$(document).ready(function() {
$("#newGame").click(function() {
player1Name = $("#jugador1").val();
player2Name = $("#jugador2").val();
gamesSessions = {
sessionID: {
gameID: {
player1Name: player1Name,
player2Name: player2Name
}
}
};
});
});