1 00:00:01,910 --> 00:00:04,680 Welcome back, my friends will come to another lecture. 2 00:00:04,700 --> 00:00:11,600 This is an important lecture because we got to start working on the module that we haven't touched yet. 3 00:00:12,020 --> 00:00:14,480 And that module is called calories controller. 4 00:00:14,810 --> 00:00:24,350 And these count calories controller will be four for all of the things that are related with calories, 5 00:00:24,470 --> 00:00:26,960 adding, burning calories, storing the calories. 6 00:00:27,230 --> 00:00:28,310 And we need to talk. 7 00:00:28,310 --> 00:00:29,760 How are we going to store this data? 8 00:00:29,840 --> 00:00:30,130 All right. 9 00:00:30,350 --> 00:00:37,730 So we know that we are returning object with some data from the form, what the user have input it, 10 00:00:38,090 --> 00:00:40,320 but we need to find a way how we can store it. 11 00:00:40,820 --> 00:00:50,090 So one of the simplest way that we can store calories for different for four different burning or adding 12 00:00:50,360 --> 00:00:52,580 is to use Herries. 13 00:00:52,730 --> 00:01:02,150 And yeah, we can just use and there is so we can create two areas here, for example, variable add 14 00:01:02,150 --> 00:01:05,730 calories and that will be an empty array. 15 00:01:05,750 --> 00:01:11,180 We have to initialize it to an empty array and sugar like that. 16 00:01:11,180 --> 00:01:14,690 And the second one for will be for the burn calories. 17 00:01:14,700 --> 00:01:15,070 Right. 18 00:01:16,940 --> 00:01:20,900 But I'm not going to waste your time and I'm going to just cut to the main part. 19 00:01:21,680 --> 00:01:28,160 Instead of having these add calories and burn calories as a two separate area, what we can do, we 20 00:01:28,160 --> 00:01:34,040 can create an object because we're dealing with objects a lot of time so we can create an object that 21 00:01:34,040 --> 00:01:36,290 will hold these two here. 22 00:01:36,600 --> 00:01:36,990 Right. 23 00:01:37,730 --> 00:01:42,380 So are we can do this, just going to cut them and I'm going to create variable storage. 24 00:01:43,400 --> 00:01:50,530 And this actually will be an object where we hold all of our data. 25 00:01:50,530 --> 00:01:52,240 And I'm going to pass this to here. 26 00:01:52,370 --> 00:02:03,410 Now, there's not going to work in like this because inside these add calories and burn calories, they 27 00:02:03,410 --> 00:02:05,170 are related with calories. 28 00:02:05,180 --> 00:02:08,920 Doesn't matter what we do with them, they are just related with calories. 29 00:02:08,930 --> 00:02:12,260 So I can store them inside another object. 30 00:02:12,260 --> 00:02:17,450 I can create this one and I'm just going to make move that will make my life easier. 31 00:02:17,460 --> 00:02:23,000 So I'm going to say all calories and I will create an additional object here. 32 00:02:23,750 --> 00:02:28,620 And I will say I'm just going to grab this for I don't need more anymore. 33 00:02:28,670 --> 00:02:29,810 Add calories. 34 00:02:30,200 --> 00:02:34,340 It will be simple and in the other one will be simple. 35 00:02:34,340 --> 00:02:35,300 Burn, right. 36 00:02:37,500 --> 00:02:42,790 So this is what we can do and here should be comma, right? 37 00:02:44,060 --> 00:02:48,920 So this is how we we will define storage, right? 38 00:02:49,340 --> 00:02:51,500 So maybe it's a little bit confusing. 39 00:02:51,500 --> 00:03:00,560 You don't see the end right now, but we create an object that will hold all of the calories regarding 40 00:03:00,560 --> 00:03:02,150 if it's burning or adding. 41 00:03:02,340 --> 00:03:12,020 And we're going to store values for adding calories and burning inside an additional an object that 42 00:03:12,020 --> 00:03:13,460 will call all the calories. 43 00:03:13,610 --> 00:03:17,170 And we will have to here inside we will have to arrest. 44 00:03:17,300 --> 00:03:24,830 One will be for when we add in calories, the other one will hold the values for when we are burning 45 00:03:24,830 --> 00:03:26,450 calories, when we are doing an exercise. 46 00:03:26,870 --> 00:03:31,950 Now, because this is a private and I will not be able to access it. 47 00:03:31,970 --> 00:03:34,430 So what we need to do is actually we need to return it. 48 00:03:34,430 --> 00:03:34,830 Right. 49 00:03:35,270 --> 00:03:39,280 So we need to return and I'm going to see a result here. 50 00:03:39,710 --> 00:03:45,050 You don't need we don't need this one, but it's going to be good for our testing and I'm just going 51 00:03:45,050 --> 00:03:46,190 to return to storage. 52 00:03:47,890 --> 00:03:53,560 Right now, we need to discuss one more thing, the other thing that we need to discuss, everything 53 00:03:53,560 --> 00:03:58,650 here that wants to be returned will be in this public methods here. 54 00:03:58,660 --> 00:03:58,960 Right. 55 00:03:59,800 --> 00:04:05,920 So one thing that we need to discuss is actually how we are going to store them, what we are going 56 00:04:05,920 --> 00:04:06,380 to use. 57 00:04:06,700 --> 00:04:15,940 So, for example, for each gallery, we we what we need, actually, these intellectual property, 58 00:04:15,940 --> 00:04:18,310 initialise are like eight. 59 00:04:19,970 --> 00:04:22,200 So he's giving me a problem here. 60 00:04:22,880 --> 00:04:23,260 Why? 61 00:04:23,570 --> 00:04:31,340 Because he don't use equal educed, you do need to use this these Colonie, right? 62 00:04:31,640 --> 00:04:35,390 Because we're dealing with objects and this is how we write the properties. 63 00:04:35,600 --> 00:04:37,910 OK, that should be done fixed. 64 00:04:38,840 --> 00:04:43,820 So if you if I if it caused some misunderstanding. 65 00:04:43,820 --> 00:04:48,620 But that's pretty much when you copy and paste things right now here we need to work. 66 00:04:50,180 --> 00:04:57,920 We need to find a very easy solution because each gallery look at this, each gallery I will form, 67 00:04:57,920 --> 00:05:02,270 it's telling us we need to have a type description, quantity, calories. 68 00:05:02,270 --> 00:05:02,590 Right. 69 00:05:03,290 --> 00:05:11,690 But each and every calorie should have unique and separate identifier, whether it's for food or for 70 00:05:11,690 --> 00:05:12,410 exercise. 71 00:05:12,710 --> 00:05:14,690 They need to have some identifier. 72 00:05:14,840 --> 00:05:22,280 And by an identifier, I mean they need to have unique I.D. So the best way, again, is to use an object 73 00:05:22,280 --> 00:05:26,750 to hold this data and object for adding calories, an object for burning calories. 74 00:05:27,050 --> 00:05:35,540 But the solution is that we can use function constructor here and when we having functions constructor's, 75 00:05:35,750 --> 00:05:39,890 we can create and more instances of add calories object. 76 00:05:39,890 --> 00:05:40,220 Right. 77 00:05:40,610 --> 00:05:43,280 Instead of having tons of objects. 78 00:05:43,460 --> 00:05:45,620 That's why the functions constructor would there. 79 00:05:45,740 --> 00:05:53,300 So we can easily use we can write them and we can usually instantiate them and we can use as many objects 80 00:05:53,300 --> 00:05:53,980 as we need. 81 00:05:54,170 --> 00:05:54,530 Right. 82 00:05:54,800 --> 00:05:56,230 So how are we going to write this function? 83 00:05:56,550 --> 00:06:03,710 I hope you understand why we didn't learn, for example, function constructor before, because now 84 00:06:03,890 --> 00:06:04,880 we need to use it. 85 00:06:04,880 --> 00:06:06,830 And this is the way we write the functions. 86 00:06:06,830 --> 00:06:11,660 Constructor right now, this function constructor will be for adding calories. 87 00:06:11,930 --> 00:06:14,540 She's going to make a new one for burning calories. 88 00:06:14,540 --> 00:06:14,790 Right. 89 00:06:15,080 --> 00:06:20,020 If they start with a capital letter right now, they do have ideas. 90 00:06:20,150 --> 00:06:21,670 They do have the description. 91 00:06:22,260 --> 00:06:22,730 What else? 92 00:06:22,730 --> 00:06:25,370 We have calories in quantity. 93 00:06:25,700 --> 00:06:26,090 Right. 94 00:06:26,600 --> 00:06:26,990 Which is good. 95 00:06:26,990 --> 00:06:29,920 Copy the same on the same goes for burning calories. 96 00:06:30,140 --> 00:06:33,280 It's a pretty much identical in how we write them. 97 00:06:33,980 --> 00:06:40,300 We use these that idea it will be equal to I'd write these, that description. 98 00:06:40,310 --> 00:06:48,320 It will be equal to the description and what else we have these that calories equal to the calories. 99 00:06:50,030 --> 00:06:50,660 Come on. 100 00:06:51,560 --> 00:06:52,400 It's messing with me. 101 00:06:52,430 --> 00:06:53,540 This is not quantity. 102 00:06:56,030 --> 00:07:02,060 It will be equal to the quantity that we have passed here through these parameters, and I'm going to 103 00:07:02,060 --> 00:07:03,860 copy this one, I'm going to save my time. 104 00:07:03,860 --> 00:07:04,600 I'm going to save it. 105 00:07:04,820 --> 00:07:08,240 So I do have now two functions constructor's. 106 00:07:09,110 --> 00:07:19,190 And remember, before we did have the methods and you write those methods inside the property, prototype 107 00:07:19,190 --> 00:07:21,870 property and after that, all of the instances. 108 00:07:21,870 --> 00:07:24,010 So how we instance actually remember. 109 00:07:24,320 --> 00:07:31,940 So, for example, were, I don't know, at sea, it will be equal to new ad Kalari. 110 00:07:31,940 --> 00:07:33,770 That's how we tried this one. 111 00:07:33,770 --> 00:07:38,590 And we're passing here like one five and I'm not going to show it to you right now. 112 00:07:38,600 --> 00:07:40,460 So this is how we create an object. 113 00:07:40,700 --> 00:07:42,800 We instantiate an object from this. 114 00:07:42,800 --> 00:07:43,460 If you haven't. 115 00:07:43,670 --> 00:07:44,400 If you forgot. 116 00:07:44,810 --> 00:07:45,380 Don't worry. 117 00:07:45,380 --> 00:07:47,500 We will refresh your memory like this. 118 00:07:48,050 --> 00:07:49,050 So that's pretty much it. 119 00:07:49,310 --> 00:07:53,210 This is how our calories module controller will look like. 120 00:07:54,410 --> 00:08:01,580 We will have function constructor for both and we have a storage will restore from each objects that 121 00:08:01,580 --> 00:08:03,080 we create here. 122 00:08:03,490 --> 00:08:03,830 Right. 123 00:08:04,010 --> 00:08:11,270 And we will do that one in this areas in the lecture now we return to storage so we can just check if 124 00:08:11,480 --> 00:08:13,910 calories control or not result. 125 00:08:14,300 --> 00:08:18,170 And that should return an object called all calories. 126 00:08:18,170 --> 00:08:21,430 Right, because it's we are returning the storage. 127 00:08:22,130 --> 00:08:23,950 So that is pretty much cool. 128 00:08:24,260 --> 00:08:28,220 Now, we do have inside all calories. 129 00:08:28,400 --> 00:08:34,030 We do have an array that is empty when you have another burn area that is empty as well. 130 00:08:34,040 --> 00:08:34,360 Right. 131 00:08:34,370 --> 00:08:41,390 When we feel some data inside, you will see this and it will be different. 132 00:08:41,390 --> 00:08:43,220 But we're going to do the targeting. 133 00:08:43,220 --> 00:08:46,400 We're going to just in here and miss something. 134 00:08:46,880 --> 00:08:51,890 But don't worry, I don't want to put the top here, but we're going to use that type. 135 00:08:52,070 --> 00:08:52,610 This type. 136 00:08:53,510 --> 00:09:00,320 Oops, sorry, we're going to use the tab here, determine if it's food or exercise, then we're going 137 00:09:00,320 --> 00:09:03,170 to save in a separate area. 138 00:09:03,260 --> 00:09:06,230 So I hope you understand I'm not using the type here. 139 00:09:07,220 --> 00:09:13,400 It's not necessary because that that we should we we don't care where it's stored because it will go 140 00:09:13,400 --> 00:09:17,360 straight to its it's airy. 141 00:09:17,630 --> 00:09:19,940 And this time we will use it. 142 00:09:20,090 --> 00:09:23,420 We will check whether it's a food, then we will add it. 143 00:09:23,420 --> 00:09:25,490 If it's exercise then we will burn it. 144 00:09:25,610 --> 00:09:27,290 Right, then we will burn calories. 145 00:09:27,440 --> 00:09:34,640 But that is for the next lecture and we will see how we can add an item in that will be something special 146 00:09:34,910 --> 00:09:37,760 because our application is starting to make sense. 147 00:09:37,900 --> 00:09:39,770 Our application is starting to grow. 148 00:09:40,010 --> 00:09:41,840 Yeah, we have done a lot of things. 149 00:09:41,840 --> 00:09:48,830 So if you go from here until there, you will see that we have done a lot of things and put a comments, 150 00:09:49,800 --> 00:09:52,970 the comments in your report in your from you. 151 00:09:53,150 --> 00:09:55,400 I would put as much as I can. 152 00:09:55,400 --> 00:10:00,410 But you should also put your comments because you can refer back to those comments in each and every 153 00:10:00,410 --> 00:10:07,640 lecture you can probably copy and create here new file called Lecture One and see what we have done 154 00:10:07,640 --> 00:10:08,300 in this lecture. 155 00:10:08,420 --> 00:10:10,400 Another lecture, save it there. 156 00:10:10,700 --> 00:10:13,070 And you can have like a versions. 157 00:10:13,310 --> 00:10:19,190 You can see how we progressed from the first one and how we got it through to here, because in future, 158 00:10:19,190 --> 00:10:22,880 if you want to try to do it by yourself, you will not know where you need to start. 159 00:10:22,880 --> 00:10:24,230 You need to start from here. 160 00:10:25,010 --> 00:10:25,420 Right. 161 00:10:26,060 --> 00:10:27,860 We need to add event listeners. 162 00:10:27,860 --> 00:10:29,710 All you need to start from app. 163 00:10:29,720 --> 00:10:30,650 You are controller. 164 00:10:30,830 --> 00:10:31,820 That's what I'm trying to say. 165 00:10:31,970 --> 00:10:33,070 So that's pretty much it. 166 00:10:33,320 --> 00:10:36,860 I hope you enjoyed this one and I will see you in the next one.