-
Notifications
You must be signed in to change notification settings - Fork 0
/
item-controller.js
71 lines (59 loc) · 1.89 KB
/
item-controller.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// const ItemCtrl = (function(){
// // Inside, we should do the item constructor
// const Item = function(id, name, calories){
// this.id = id;
// this.name = name;
// this.calories = calories;
// }
// // Data structure / State
// const data = {
// items: [
// // {id: 0, name:"Hamburger", calories:1200},
// // {id: 1, name:"French Fries", calories:800},
// // {id: 2, name:"Soda", calories:950}
// ],
// currentItem: null,
// totalCalories: 0
// }
// // Since the previous data is private, we need to return it in order to access it for testing purposes
// // Public methods
// return {
// // Following function is for getting the items and passing them to our App controller
// getItems: function(){
// return data.items;
// },
// addItem: function(name, calories){
// // Add logic for ID
// let ID;
// if (data.items.length > 0){
// ID = data.items[data.items.length - 1].id + 1;
// } else {
// ID = 0;
// }
// // Convert calories to integer
// calories = parseInt(calories);
// // Create new item with info from inputs
// newMeal = new Item(ID, name, calories);
// // Push item to data structure.
// data.items.push(newMeal);
// // Returning the new meal for later use in variables
// return newMeal;
// },
// // Get total calories function
// getTotalCalories: () => {
// let sum = 0;
// // Loop through items and add cals
// data.items.forEach(function(item){
// sum += item.calories;
// })
// // Set total cal in data structure
// data.totalCalories = sum;
// // Return total
// return data.totalCalories;
// },
// // Method to check inner workings of data structure
// logData: function(){
// return data;
// },
// }
// })();