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.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)