OK, ladies and gentlemen, today is one of the most interesting lectures where we are going to add
our calories for the first time in the storage object that we created.
Right now, how are we going to do this?
So the idea is here to create a function with with the name at CALORIE.
And that function will be pretty much here above above the result, because we need to return the result
from adding and storing the data inside those these objects.
Right.
But if you ask yourself how we can do this first, we need here we just cancel like the input.
We just read the data first.
Right now, the second part is that we will do is pretty much, I'm going to say not read the data at
CALORIE and here I'm going to call a function.
So this function will be inside calories controller.
So I'm going to add the calories control or not add calorie might this function is not created here.
Right.
So let's create this function here.
And as I told you, this is a return.
This is just a test.
After that, we can just delete it.
But here I'm going to say at calorie like that, and I'm just going to say it's a function.
We doubt it's going to take some parameters in here.
Don't forget about this comment right now what type of parameters we need to have in order these calorie
to function.
So here, remember that in this get I'm just going to show you in this get for me.
But we did get the data from our forum, right.
So we're going to parse the same object.
So we have two options here to parse the entire object like this.
And let's go back here and we need to see form object and these form object.
We're going to see console log, for example, form object.
And I can access the type.
Right.
Let's see if it's going to work or not.
So this is one of the way I'm going to show you the type is going to be at right.
Food one one hit enter and let's see if we expect it at something we'll have.
Yeah, it will be air.
So we will have objects.
And we will have these ads, right, because that is pretty much it for this, if I go to exercise,
if I put here E, for example, if I click it again, let's refresh.
And still, for some reason, I do have that result there.
Sometimes this can be stopped.
Don't worry about it.
You need to be just learn to be patient and one one.
And here it is.
It's going to be brain, right.
This is what I would expect if I put exercise food in here that we don't need to change is going to
be.
And in this time, it's coming from where we did Kunzel like these.
Get warm.
Right, you can just.
Comin out now you can do this or you can do it like get form, input, dot type, comma.
Get for me and put that what else we need here, so I do have a description.
I do have gift for input calories and get for me food quality.
Right.
So we can do that.
But here.
Where it is, I get lost for a second here in this one.
So here we don't have object.
We have four values.
It will be a type description.
You can just change it.
You can name these parameters from this function, whatever you want.
You can just put it to the yeah.
What else type description, calories and quantities.
You can do it like this, but I'm going to just use the same names.
But you can use whatever you want.
And this will be description, and here it will be time.
So now I will not be able to use this object anymore.
First, we don't have it here, but I can straight access to type here.
Or just put a description now, it will be more interesting, right?
So I'm just going to refresh here and here for some reason, everything.
So food doesn't matter what we got to say.
Food here, one one.
And he's entertaining his food, food or hear ice cream.
It will be ice cream if I have.
Does it matter?
I'm not checking for the type anymore.
So now you know how you can pass these data that we have from the form.
And sorry, I'm thinking something else.
That's why I just go around like that so you can basically hear what I just always want to do because
I don't want to make this too long.
I'm just going to pass the entire object.
In here.
I'm just going to say, OK, input object right here, what I'm going to do is I'm going to say VoIP
type, comma, description, comma, and what else we need here.
That description, calories.
Quantity, right, and what I can do is I can say type, it will be equal to input object.
That type description will be equal to input object description calories will be
calories will be input input, object calories in quantity will be input, object quantity.
Right now this will work.
Now again, let's choose to choose the calories for it.
This will work because it grab from input object and I save it into this variable here on the left.
All right.
So I'm just going to close it.
I don't know what is happening today, but I have too many things right.
And I hate for some reason now this fire of this Google Chrome is getting out of control.
So food, ice cream.
Right.
And here it will be one.
The calories will be one seven seven.
Let's see.
Yep.
Here is the calories.
If I change the calories to two or three, it will be two three.
So that's it.
I prefer doing this way.
So I have saved all of this into a variables.
So let's move on now.
What is the idea here?
The idea here is to have two based on what we are trying to see if we are adding a calories or we are
burning calories, we are going to show based on the type.
Actually, we are going to create a new instance in here.
I'm going to see new calorie and you will see why this new calorie I mean, now, based on if I'm going
to eat condition based on the type, if the type is equal, equal to at.
Or else, if time is equal, equal to burn, right?
So I know this that is why we create this ad in burn areas, because they do have the same name and
are also in the in the HDMI.
I do have for the option I do have and this is not like random.
This is this is like that because after that you will see I'm just going to use the type, whatever
that that is and I'm going to store.
So here I'm going to use I'm going to create a new instance.
So new Kaleri and that will be equal from new app Coull some creating a new instance from ATCO object
in here.
I do want to have ideas.
So what we have is just going to copy it here.
I'm going to paste it and that's pretty much it.
Now I do have everything.
I do have the description.
I do have the calories.
I do have the quantities.
I don't have just the idea in.
So I can do it here and I can say, OK, I want to start with Idy zero.
Don't worry about the idea now because yeah, the idea should be unique, but we will start with zero
because that is a little bit longer.
A lecture that I want to explain to you.
So first I just want to add some calories, but we can copy the same thing.
If the type is a burn, then we can say burn.
We going to call that function constructor.
Right?
So we're calling the function constructor in this new gallery.
We are making a new instance.
So now we can add to our storage object.
Right.
So I'm going to pass as our burn and they we will add something to this object here.
So how we can do this, we will use the push method because this is a theory, but how are we going
to select it?
So now I have new instance here, right in this new instance will have different values.
But what I do now is just simply storage.
I'm going to call the storage and look at this.
I'm going to that structure storage all the old colorists, not categories.
And based on the type that I have, it's going to be at Allburn.
So how cool is this?
So we select based on that I have Afterburn and that's where the type is there.
So I can just simply push it.
You can use this method push and I will add new Kalari right in this new Kaleri will contain whatever
we're going to put here.
Am I clear?
Are we going to put here?
It's going to be actually there right now.
This push will add a new element at the end of the array, and that's pretty much it.
Let's save it and let's see what's happening.
So I'm going to refresh I'm going to add food when I say food one one and I'm going to add it in.
Nothing is happening.
Why?
Because.
And that is happening because we don't we are not bringing the result, we're not just bringing out
these storage.
So what I can do here, after where we add the calories, I'm going to use the same calories controller
and I'm going to print out the result.
So I hope now after every if everything is OK, so I'm going to say ice cream.
I would like to see the output there.
And still, it's not.
Running here, what we do have.
Because we need to control it, like that's why.
Right, because we just returning something so here, I'm sorry, I'm going to be at again, so food
one.
And let's add it, and here it is, we do have these all calories in now if you go inside these object,
we do have all calories object with add in Bernardy.
Now, these Adoree look at this.
If I go again in Adoree, I'm just going to go bigger here.
I do have I did zero description food and calories one right now change to something else.
Ice cream and hit enter.
Now I'm going to see that one again.
I have two items now.
Again it will be description ice cream calories one because it didn't change the calories.
Let's put something else.
Let's put here, I don't know, hamburger.
Not that I want to eat too many hamburgers.
I click enter in what you need to scroll a little bit down in order to see this.
So I do have food, ice cream and hamburger, but the negative for me is that I do have the same idea
zero and that is not ideal.
Right?
And if I refresh, it's all gone right now.
Tested out for air, for food.
So food one.
Right.
And let's do exercise exercise.
One hundred and fifty.
Let's see both of the areas now contain something.
So you go to the second.
Here it is.
Burn contains data and is going to be the ID zero X for the exercise calories and quantity in here.
It will be for food, calories and quality.
So I hope you are.
You guys love this lecture.
So what we did, we just print out the result and that result is just printed out the storage that we
have.
So what we did here, we grabbed whatever we have from the input from our form.
We because we had grabbed that far from this point, we get form from input.
We use that method to store the data here and that's why we can pass it to add calorie.
Now you need to call this add calorie here.
Otherwise it will not work.
Right, that I'm trying to tell you.
And here we are just basically saying, based on the type we are creating new instance of this function
controller, if it's and we going to create add call, if it's within you, if it's burned, you're
going to create one color.
And after that, we use the storage all calories based on the type.
Right.
And we pushing this new calorie and that will push it back through.
And as a last element is a new element at the end of the array.
So I hope you enjoy.
Now you learn that you can use only the object in here.
You need to call it.
If you use the object, it still will work, right?
Still will work instead of doing this.
But you need to take out this work and put it here, here if you want to work right in.
Also here in.
Yeah.
The rest, you know how to do it.
But I just prefer to store it in the variables and then use them.
It's more cleaner like that.
Or you can put the variables here like this and then you can use it here.
So thank you very much.
I hope you enjoy this and I will see you in the next one.
Where are we going to work?
How we can create a unique idea for every new entry, for every new Kalari entry for regardless regardless
if it's for adding or burning new calories.
Right.
So thank you very much.
And I see you in the next one.