var activePlayer = 0;
var currentScore0 = 0;
var currentScore1 = 0 ;
var player ="currentScore"+activePlayer;
This gives me a string "currentScore0" how do I get the value from the variable currentScore0
var activePlayer = 0;
var currentScore0 = 0;
var currentScore1 = 0 ;
var player ="currentScore"+activePlayer;
This gives me a string "currentScore0" how do I get the value from the variable currentScore0
You can use window["currentScore"+activePlayer]
to access that variable's value but you should find a better way of storing this info so it will be easier to access it.
Here is an example of storing the info:
var players = [{
id: 1,
score: 0,
active: true
}, {
id: 2,
score: 0,
active: false
}, getPlayer: function(id){
return this.find(player => player.id == id);
}];
Then you can do:
var playerOneScore = players.getPlayer(1).score;