How can I make an object reference?
How can I make an object reference?
var $playerChoice1 = Math.floor((Math.random()*5+1));
var $playerChoice2 = Math.floor((Math.random()*(10-6+1)+6));
var $playmaking1 = $player+$playerChoice1.playmaking;
var $playmaking2 = $player+$playerChoice2.playmaking;
var $rebounding1 = $player+$playerChoice1.rebounding;
var $rebounding2 = $player+$playerChoice2.rebounding;
I'd like to get values from randomly chosen $player objects ($player1, $player2, .., $player9, $player10). First player is chosen from 1 to 5 and the other from 6 to 10. My code doesn't work (of course). How should I deal with it?
1 Answer
1
var players = [...]; // ten players
var $playerChoice1 = Math.floor((Math.random() * 5)); // range [0, 4]
var $playerChoice2 = Math.floor((Math.random() * 5 + 5)); // range [5, 9]
var $playmaking1 = players[$playerChoice1].playmaking;
var $playmaking2 = players[$playerChoice2].playmaking;
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.