Welcome back, my friend.
Welcome to another lecture's show.
Before doing anything else, I just want to fix our form.
So when I say for my money, I'll fix the forum.
The way we submit things, it's like here.
So if I don't if I click enter now or the whatever, you click on the mouse because we have to event
listeners.
It will work for both of them.
Yeah, but the thing is that look at what we are doing.
We just having and actually this part, everything else is empty.
No.
Also the calories and the quantity are strings.
So even if I had here food one hundred and fifty and I just just want to show you something, there
will be still um still considered as string's.
So we need to change this one.
By the way, you can change this here.
You can put a placeholder where it is.
It is placeholder one.
Right.
And before we didn't have any placeholders but that is considered a string.
You still need to manually insert one, right?
Yeah.
What we can do here, we can just put a negative number in minus six point, I don't know, description
for it.
It will still work.
So we don't want this to happen in our application.
We don't want a negative values.
We can restrict it through this form here.
But I just want to do it through JavaScript.
Right.
So let's change it where we get this.
When we are getting here now, we have two things that we need to change.
We getting the calories and a quantity.
And I want the calories to be considered as float's as a decimal.
Right.
And there is a function called Parslow that we can use it here.
And that function passes this part here that that returns a string and returns to a floating point number.
So we just need to do one line pass float and put this one inside of these brackets and save it.
Why?
Again, because calories, I just want to have decimal number like seventeen point eight, for example.
Right.
And look at what's happening now.
It's not not any more string.
It is proper number.
So the first float returns.
So this function pass float, the partial function passes a string and returns a floating point number.
Now, also, there is a one more function here in here.
We're not going to put one point one.
That's not going to happen because we can't eat.
For example, we can't say, OK, half a burger.
That's maybe you can, but in my case, that doesn't make any sense.
So I just want to have a real number or integer.
So there's a function called Pass in and I'm going to use it here in this pass in function parses of
string and returns as integer.
So let's save it.
Yeah.
Let's go back here and let's say, OK, food one in one hundred and fifty two point or point three.
So now I do have these hundred fifty two point three and this as a no it's not string anymore.
So you can see how easy it is to change from a string to a number and we are returning that this object
with those values.
So there's nothing, nothing special about this, but it will save a huge time for us in order when
we save this where we store this data somewhere in that with this add calories function, we need to
do something.
Now, also, what I don't want to happen is I want to have this here negative value.
I don't want to happen.
Right, because here it oh, now it's working and we don't have any way to stop it.
So where we can stop this one.
So here I'm cancelling lock the get form input and that is from this function here result.
Right.
The object.
But what we can do, we can just create some if condition here and we can check if get form input for
example.
So what we can check here is if that description is not empty.
Right.
It's not empty string because the description is a string.
So let's test it out and I'm going to wrap this one in here.
I'm going to say ls council and you can say you have empty description.
Feel right.
Just to test it out now, let's see what will happen.
So if I click now enter, I do have only deselect this manually, but you have empty description feel
right.
But if I do enter here, food, everything else, it's not there.
And we don't have values here, but it's still we're going to work because we are just checking for
the food, ok.
Anything, not a number.
Any end means not a number and we have a little function for that to check.
So I'm going to I'm going to tell you that is any and there is a function call is.
But here we need to concatenate and and say is an eight and so is any method determines whether a value
is an or not a number.
So this method returns.
True.
If the value is of the total number and equates to not a number, otherwise it will return false.
I know that's a little bit confusing.
Well, let's test it out here in the console and I'm going to show you.
So let's make it bigger.
And what I want to do, what I want to say here is anyon.
And I'm going to pass here a number and this will return false.
So it's an end method determines if the whether the value side is not a number.
Right.
And this is actually a number.
This matter indeed is true.
If the values, the type of numbers.
So what we can do, we can just put this one.
Let's just test this one.
One more thing.
And if I put here string, what do you think will happen?
It will return.
True.
So I want this function to change it in every time I have a number to be true.
Right.
So how can I do exclamation mark?
And so I negate is anything and when I put no now it will return me true.
And when I put a screen now it will return me false.
Right.
So whenever I put here, it will return false if it's not a number, right?
So that actually returned.
True, but I just want to have so by the way, here, we will not be able to put a string just I'm just
telling you some pressing SDF so we are not able to put a screen.
Why?
Because in the index I do have this type number and in that browser in Firefox or in Google Chrome,
it is working like that.
It's not allowing you to put a string here.
That's one way you can make this application it.
So it's not a number in what we can do here.
We're going to say get for input, not calories.
Right.
So let's see if that will work.
Now, just going to remove this one here and remove everything.
And I'm just going to put a food here.
I'm going to click enter.
You have empty description, fill in.
Why is this happening?
Because here here I don't have this one now, 15.
Now it will go any inside will enter.
So I do have you have an empty description fill and I'm checking two things here.
That's why to go there, because one of them was not was not a number was actually an empty string.
So if I go back here, it will you have an empty so we can change it.
You have an empty fields.
Or make better, let the better do this so you can say, please feel the form correctly, but we're
going to remove these Ellspermann, please feel the form correctly.
Like that and make it A, B, C, so now it will not go there.
Please fill in the form, collect correctly food in calories.
How cool is this?
They're working now.
I need to check one more thing here.
If I put a zero, it will still work.
Right.
And I don't want that to happen.
So what I can do, I can check if the get for input calories is bigger than zero.
Right.
That will fix two things.
It will fix the negative values that we can enter minus and it will fix if it's zero.
So I'm just asking these value to be bigger and positive.
Right.
You know, I save food, click, enter.
It's working.
Let's try with minus should not work.
Please fill in the form correctly.
If we put a zero areas he's saying to here it's not working.
OK, so we fix a couple of scenarios here.
We need to do this one.
Right.
We're not worried about the selection because it's already been preselected.
He's been selected to add.
But if you have a preference to do the burn, just cut this part here and put it here and every time
you will be selected the burn part.
Now, one more thing we need to do, we need to check for.
I'm just going to copy this one.
I'm just going to copy even with that and operator so now get put quantity.
OK, not should not I should not go there.
So I should go here.
Quantity.
Better to make it like this, and quantity should be bigger than zero as well.
OK, no, let's just it that when I click here.
Please fill the form food again.
It's not working.
Just the calories.
It's not working.
Put here one and it will work.
Now I do have like just test it out.
If I put zero will not work.
If I put minus one still it will not work.
So now the form is super secure.
I mean it's not secure.
It doesn't allow us to to get input.
That is not valid for our calculation.
For example, I'm not being able to put minus 150 calories.
Right.
Because that means that I'm going to burn and I should select this and I should again put a positive
number, because after that, we will subtract that number from this total here.
Right.
So that's pretty much it for this lecture.
What we have done, I'm just going to be super, super quick.
So we use Borislow and pass in to convert that string to an integer.
That's why we have this now.
A hundred and fifty and this also.
The add calories where it is in the add calories, we did check in this function if the description
is empty, if this is a number.
So if it's not number eight, that's why this sign is here.
Operator, otherwise, if it's greater than zero, so we get rid of that negative values and zeros and
we have done the same thing for quantity.
Now we can take care for the rest of the hour.
Logic in that, do something with adding calories.
So I hope you enjoyed this lecture.
It wasn't something special, but we just still managed to do a couple of things that will make a bucks
in future.
We will have to do them in future.
So thank you very much.
And now we'll see you in the next one.
Also, we're not going to use this one that was just for testing.
You can comment out or you can delete that one.
Right.
So I'm just going to delete and maybe in future I'm going to show you something.
For example, if you want to get here some message, you can write message.
And after after we finish this project, you can put your div with a with a class message.
And when the form is not good, you can just display that one.
Right.
Which you can select with a selector, but that is for your for you to do after we finish this project.
Right.
Because it's not going to be complex, because you can learn a lot of things and you will know how to
do them.
So thank you very much and I will see you in the next one.