-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
36 lines (30 loc) · 1.33 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
(function() {
var app = angular.module('Flatlanders', []);
app.controller('StoreController', function($scope){
$scope.amountPurchased = 0;
$scope.gems = [
{item: "Ruby", quantity: 15, price: 3499.98, numberPurchased: 0, index: 0},
{item: "Diamond", quantity: 10, price: 8753.98, numberPurchased: 0, index: 1},
{item: "Emerald", quantity: 87, price: 2343.98, numberPurchased: 0, index: 2},
{item: "Crystal", quantity: 34, price: 123.98, numberPurchased: 0, index: 3},
{item: "Gold", quantity: 105, price: 6735.98, numberPurchased: 0, index: 4}
]
$scope.buy = function(index) {
$scope.gems[index].numberPurchased++;
$scope.gems[index].quantity--;
$scope.amountPurchased += $scope.gems[index].price;
}
$scope.sell = function(index) {
$scope.gems[index].numberPurchased--;
$scope.gems[index].quantity++;
$scope.amountPurchased -= $scope.gems[index].price;
}
$scope.getOnlyPurchased = function(gem) {
// Do some tests
if(gem.numberPurchased > 0) {
return true; // this will be listed in the results
}
return false; // otherwise it won't be within the results
};
});
})();