I'm currently building an app where you can make neat trading cards as my introduction into AngularJS. Currently I have a set array of stats that people can choose from to build onto their character, but I'd like to make the feature more random/automated.
How do I create a function to randomly go through and assign one of the values in my array?
Currently I am spitting out the buttons to set the stats this way:
<p ng-repeat="power in cardPowers">
<a href="" ng-click="cardStats(power.attack,power.defense,power.cost)">
{{power.name | uppercase}}
</a>
</p>
And my stats array and function to set them:
$scope.cardPowers = [
{
name: "balanced-low",
attack: 800,
defense: 800,
cost: 2
},
{
name: "balanced-medium",
attack: 1500,
defense: 1500,
cost: 4
},
{
name: "balanced-high",
attack: 2500,
defense: 2500,
cost: 7
},
{
name: "high-offense",
attack: 2500,
defense: 1000,
cost: 5
},
{
name: "base-offense",
attack: 1500,
defense: 1000,
cost: 3
},
{
name: "base-defense",
attack: 1000,
defense: 1500,
cost: 3
},
{
name: "high-offense",
attack: 2200,
defense: 1000,
cost: 5
},
{
name: "high-defense",
attack: 1000,
defense: 2500,
cost: 4
},
{
name: "high-offense-defense",
attack: 2200,
defense: 2500,
cost: 6
}
];
$scope.cardStats = function(attack, defense, cost){
$scope.attack = attack;
$scope.defense = defense;
$scope.cost = cost;
};