Welcome back, my friends will come to another lecture.
This is an important lecture because we got to start working on the module that we haven't touched yet.
And that module is called calories controller.
And these count calories controller will be four for all of the things that are related with calories,
adding, burning calories, storing the calories.
And we need to talk.
How are we going to store this data?
All right.
So we know that we are returning object with some data from the form, what the user have input it,
but we need to find a way how we can store it.
So one of the simplest way that we can store calories for different for four different burning or adding
is to use Herries.
And yeah, we can just use and there is so we can create two areas here, for example, variable add
calories and that will be an empty array.
We have to initialize it to an empty array and sugar like that.
And the second one for will be for the burn calories.
Right.
But I'm not going to waste your time and I'm going to just cut to the main part.
Instead of having these add calories and burn calories as a two separate area, what we can do, we
can create an object because we're dealing with objects a lot of time so we can create an object that
will hold these two here.
Right.
So are we can do this, just going to cut them and I'm going to create variable storage.
And this actually will be an object where we hold all of our data.
And I'm going to pass this to here.
Now, there's not going to work in like this because inside these add calories and burn calories, they
are related with calories.
Doesn't matter what we do with them, they are just related with calories.
So I can store them inside another object.
I can create this one and I'm just going to make move that will make my life easier.
So I'm going to say all calories and I will create an additional object here.
And I will say I'm just going to grab this for I don't need more anymore.
Add calories.
It will be simple and in the other one will be simple.
Burn, right.
So this is what we can do and here should be comma, right?
So this is how we we will define storage, right?
So maybe it's a little bit confusing.
You don't see the end right now, but we create an object that will hold all of the calories regarding
if it's burning or adding.
And we're going to store values for adding calories and burning inside an additional an object that
will call all the calories.
And we will have to here inside we will have to arrest.
One will be for when we add in calories, the other one will hold the values for when we are burning
calories, when we are doing an exercise.
Now, because this is a private and I will not be able to access it.
So what we need to do is actually we need to return it.
Right.
So we need to return and I'm going to see a result here.
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
to return to storage.
Right now, we need to discuss one more thing, the other thing that we need to discuss, everything
here that wants to be returned will be in this public methods here.
Right.
So one thing that we need to discuss is actually how we are going to store them, what we are going
to use.
So, for example, for each gallery, we we what we need, actually, these intellectual property,
initialise are like eight.
So he's giving me a problem here.
Why?
Because he don't use equal educed, you do need to use this these Colonie, right?
Because we're dealing with objects and this is how we write the properties.
OK, that should be done fixed.
So if you if I if it caused some misunderstanding.
But that's pretty much when you copy and paste things right now here we need to work.
We need to find a very easy solution because each gallery look at this, each gallery I will form,
it's telling us we need to have a type description, quantity, calories.
Right.
But each and every calorie should have unique and separate identifier, whether it's for food or for
exercise.
They need to have some identifier.
And by an identifier, I mean they need to have unique I.D. So the best way, again, is to use an object
to hold this data and object for adding calories, an object for burning calories.
But the solution is that we can use function constructor here and when we having functions constructor's,
we can create and more instances of add calories object.
Right.
Instead of having tons of objects.
That's why the functions constructor would there.
So we can easily use we can write them and we can usually instantiate them and we can use as many objects
as we need.
Right.
So how are we going to write this function?
I hope you understand why we didn't learn, for example, function constructor before, because now
we need to use it.
And this is the way we write the functions.
Constructor right now, this function constructor will be for adding calories.
She's going to make a new one for burning calories.
Right.
If they start with a capital letter right now, they do have ideas.
They do have the description.
What else?
We have calories in quantity.
Right.
Which is good.
Copy the same on the same goes for burning calories.
It's a pretty much identical in how we write them.
We use these that idea it will be equal to I'd write these, that description.
It will be equal to the description and what else we have these that calories equal to the calories.
Come on.
It's messing with me.
This is not quantity.
It will be equal to the quantity that we have passed here through these parameters, and I'm going to
copy this one, I'm going to save my time.
I'm going to save it.
So I do have now two functions constructor's.
And remember, before we did have the methods and you write those methods inside the property, prototype
property and after that, all of the instances.
So how we instance actually remember.
So, for example, were, I don't know, at sea, it will be equal to new ad Kalari.
That's how we tried this one.
And we're passing here like one five and I'm not going to show it to you right now.
So this is how we create an object.
We instantiate an object from this.
If you haven't.
If you forgot.
Don't worry.
We will refresh your memory like this.
So that's pretty much it.
This is how our calories module controller will look like.
We will have function constructor for both and we have a storage will restore from each objects that
we create here.
Right.
And we will do that one in this areas in the lecture now we return to storage so we can just check if
calories control or not result.
And that should return an object called all calories.
Right, because it's we are returning the storage.
So that is pretty much cool.
Now, we do have inside all calories.
We do have an array that is empty when you have another burn area that is empty as well.
Right.
When we feel some data inside, you will see this and it will be different.
But we're going to do the targeting.
We're going to just in here and miss something.
But don't worry, I don't want to put the top here, but we're going to use that type.
This type.
Oops, sorry, we're going to use the tab here, determine if it's food or exercise, then we're going
to save in a separate area.
So I hope you understand I'm not using the type here.
It's not necessary because that that we should we we don't care where it's stored because it will go
straight to its it's airy.
And this time we will use it.
We will check whether it's a food, then we will add it.
If it's exercise then we will burn it.
Right, then we will burn calories.
But that is for the next lecture and we will see how we can add an item in that will be something special
because our application is starting to make sense.
Our application is starting to grow.
Yeah, we have done a lot of things.
So if you go from here until there, you will see that we have done a lot of things and put a comments,
the comments in your report in your from you.
I would put as much as I can.
But you should also put your comments because you can refer back to those comments in each and every
lecture you can probably copy and create here new file called Lecture One and see what we have done
in this lecture.
Another lecture, save it there.
And you can have like a versions.
You can see how we progressed from the first one and how we got it through to here, because in future,
if you want to try to do it by yourself, you will not know where you need to start.
You need to start from here.
Right.
We need to add event listeners.
All you need to start from app.
You are controller.
That's what I'm trying to say.
So that's pretty much it.
I hope you enjoyed this one and I will see you in the next one.