1 00:00:01,500 --> 00:00:02,340 Welcome back, my friend. 2 00:00:02,370 --> 00:00:04,830 Welcome to another lecture's show. 3 00:00:04,830 --> 00:00:08,930 Before doing anything else, I just want to fix our form. 4 00:00:09,570 --> 00:00:12,240 So when I say for my money, I'll fix the forum. 5 00:00:12,240 --> 00:00:14,740 The way we submit things, it's like here. 6 00:00:14,760 --> 00:00:22,190 So if I don't if I click enter now or the whatever, you click on the mouse because we have to event 7 00:00:22,200 --> 00:00:22,770 listeners. 8 00:00:23,100 --> 00:00:24,800 It will work for both of them. 9 00:00:24,840 --> 00:00:27,510 Yeah, but the thing is that look at what we are doing. 10 00:00:27,930 --> 00:00:32,780 We just having and actually this part, everything else is empty. 11 00:00:32,970 --> 00:00:33,390 No. 12 00:00:34,260 --> 00:00:37,490 Also the calories and the quantity are strings. 13 00:00:37,740 --> 00:00:45,540 So even if I had here food one hundred and fifty and I just just want to show you something, there 14 00:00:45,540 --> 00:00:52,230 will be still um still considered as string's. 15 00:00:52,260 --> 00:00:53,400 So we need to change this one. 16 00:00:53,730 --> 00:00:57,270 By the way, you can change this here. 17 00:00:57,270 --> 00:00:59,070 You can put a placeholder where it is. 18 00:00:59,460 --> 00:01:01,320 It is placeholder one. 19 00:01:01,410 --> 00:01:01,830 Right. 20 00:01:02,250 --> 00:01:06,330 And before we didn't have any placeholders but that is considered a string. 21 00:01:06,360 --> 00:01:09,690 You still need to manually insert one, right? 22 00:01:10,170 --> 00:01:10,620 Yeah. 23 00:01:10,740 --> 00:01:17,850 What we can do here, we can just put a negative number in minus six point, I don't know, description 24 00:01:17,850 --> 00:01:18,710 for it. 25 00:01:18,720 --> 00:01:19,590 It will still work. 26 00:01:19,590 --> 00:01:22,080 So we don't want this to happen in our application. 27 00:01:22,080 --> 00:01:23,220 We don't want a negative values. 28 00:01:23,460 --> 00:01:25,830 We can restrict it through this form here. 29 00:01:26,100 --> 00:01:27,930 But I just want to do it through JavaScript. 30 00:01:28,020 --> 00:01:28,380 Right. 31 00:01:28,710 --> 00:01:30,710 So let's change it where we get this. 32 00:01:30,720 --> 00:01:34,800 When we are getting here now, we have two things that we need to change. 33 00:01:35,550 --> 00:01:37,620 We getting the calories and a quantity. 34 00:01:37,860 --> 00:01:43,380 And I want the calories to be considered as float's as a decimal. 35 00:01:43,680 --> 00:01:44,100 Right. 36 00:01:44,400 --> 00:01:48,540 And there is a function called Parslow that we can use it here. 37 00:01:48,840 --> 00:01:58,770 And that function passes this part here that that returns a string and returns to a floating point number. 38 00:01:59,100 --> 00:02:10,110 So we just need to do one line pass float and put this one inside of these brackets and save it. 39 00:02:10,530 --> 00:02:11,040 Why? 40 00:02:11,040 --> 00:02:16,620 Again, because calories, I just want to have decimal number like seventeen point eight, for example. 41 00:02:16,620 --> 00:02:16,950 Right. 42 00:02:17,820 --> 00:02:19,350 And look at what's happening now. 43 00:02:19,350 --> 00:02:22,410 It's not not any more string. 44 00:02:22,530 --> 00:02:25,230 It is proper number. 45 00:02:25,590 --> 00:02:27,840 So the first float returns. 46 00:02:28,620 --> 00:02:35,810 So this function pass float, the partial function passes a string and returns a floating point number. 47 00:02:36,180 --> 00:02:39,780 Now, also, there is a one more function here in here. 48 00:02:39,780 --> 00:02:41,350 We're not going to put one point one. 49 00:02:41,580 --> 00:02:44,280 That's not going to happen because we can't eat. 50 00:02:44,280 --> 00:02:47,580 For example, we can't say, OK, half a burger. 51 00:02:47,880 --> 00:02:52,110 That's maybe you can, but in my case, that doesn't make any sense. 52 00:02:52,290 --> 00:02:55,440 So I just want to have a real number or integer. 53 00:02:55,530 --> 00:03:04,410 So there's a function called Pass in and I'm going to use it here in this pass in function parses of 54 00:03:04,410 --> 00:03:06,360 string and returns as integer. 55 00:03:06,570 --> 00:03:07,530 So let's save it. 56 00:03:07,770 --> 00:03:08,070 Yeah. 57 00:03:08,230 --> 00:03:17,540 Let's go back here and let's say, OK, food one in one hundred and fifty two point or point three. 58 00:03:18,030 --> 00:03:26,250 So now I do have these hundred fifty two point three and this as a no it's not string anymore. 59 00:03:26,520 --> 00:03:35,040 So you can see how easy it is to change from a string to a number and we are returning that this object 60 00:03:35,220 --> 00:03:36,060 with those values. 61 00:03:36,060 --> 00:03:44,730 So there's nothing, nothing special about this, but it will save a huge time for us in order when 62 00:03:44,730 --> 00:03:51,300 we save this where we store this data somewhere in that with this add calories function, we need to 63 00:03:51,540 --> 00:03:52,230 do something. 64 00:03:52,500 --> 00:03:59,190 Now, also, what I don't want to happen is I want to have this here negative value. 65 00:03:59,550 --> 00:04:00,540 I don't want to happen. 66 00:04:00,540 --> 00:04:06,480 Right, because here it oh, now it's working and we don't have any way to stop it. 67 00:04:06,720 --> 00:04:08,300 So where we can stop this one. 68 00:04:08,580 --> 00:04:16,830 So here I'm cancelling lock the get form input and that is from this function here result. 69 00:04:16,830 --> 00:04:17,080 Right. 70 00:04:17,080 --> 00:04:17,510 The object. 71 00:04:17,760 --> 00:04:27,990 But what we can do, we can just create some if condition here and we can check if get form input for 72 00:04:27,990 --> 00:04:28,560 example. 73 00:04:28,770 --> 00:04:36,990 So what we can check here is if that description is not empty. 74 00:04:36,990 --> 00:04:37,380 Right. 75 00:04:37,380 --> 00:04:40,080 It's not empty string because the description is a string. 76 00:04:40,080 --> 00:04:44,640 So let's test it out and I'm going to wrap this one in here. 77 00:04:44,880 --> 00:04:57,000 I'm going to say ls council and you can say you have empty description. 78 00:04:58,680 --> 00:04:59,840 Feel right. 79 00:05:00,110 --> 00:05:03,230 Just to test it out now, let's see what will happen. 80 00:05:03,470 --> 00:05:10,550 So if I click now enter, I do have only deselect this manually, but you have empty description feel 81 00:05:10,790 --> 00:05:11,090 right. 82 00:05:11,090 --> 00:05:16,550 But if I do enter here, food, everything else, it's not there. 83 00:05:16,590 --> 00:05:20,630 And we don't have values here, but it's still we're going to work because we are just checking for 84 00:05:20,630 --> 00:05:21,500 the food, ok. 85 00:05:21,890 --> 00:05:24,110 Anything, not a number. 86 00:05:24,110 --> 00:05:28,840 Any end means not a number and we have a little function for that to check. 87 00:05:29,330 --> 00:05:36,350 So I'm going to I'm going to tell you that is any and there is a function call is. 88 00:05:37,330 --> 00:05:47,000 But here we need to concatenate and and say is an eight and so is any method determines whether a value 89 00:05:47,000 --> 00:05:49,430 is an or not a number. 90 00:05:49,550 --> 00:05:51,380 So this method returns. 91 00:05:51,380 --> 00:05:51,830 True. 92 00:05:52,760 --> 00:05:59,900 If the value is of the total number and equates to not a number, otherwise it will return false. 93 00:06:00,500 --> 00:06:01,970 I know that's a little bit confusing. 94 00:06:02,000 --> 00:06:05,460 Well, let's test it out here in the console and I'm going to show you. 95 00:06:05,700 --> 00:06:09,710 So let's make it bigger. 96 00:06:10,460 --> 00:06:15,050 And what I want to do, what I want to say here is anyon. 97 00:06:15,910 --> 00:06:20,460 And I'm going to pass here a number and this will return false. 98 00:06:21,260 --> 00:06:27,350 So it's an end method determines if the whether the value side is not a number. 99 00:06:27,350 --> 00:06:27,670 Right. 100 00:06:27,770 --> 00:06:29,750 And this is actually a number. 101 00:06:29,760 --> 00:06:30,980 This matter indeed is true. 102 00:06:31,100 --> 00:06:32,900 If the values, the type of numbers. 103 00:06:32,920 --> 00:06:36,140 So what we can do, we can just put this one. 104 00:06:36,410 --> 00:06:37,490 Let's just test this one. 105 00:06:37,610 --> 00:06:38,390 One more thing. 106 00:06:39,050 --> 00:06:43,790 And if I put here string, what do you think will happen? 107 00:06:45,170 --> 00:06:45,890 It will return. 108 00:06:45,890 --> 00:06:46,270 True. 109 00:06:46,760 --> 00:06:52,250 So I want this function to change it in every time I have a number to be true. 110 00:06:52,260 --> 00:06:52,610 Right. 111 00:06:52,640 --> 00:06:54,860 So how can I do exclamation mark? 112 00:06:54,860 --> 00:07:02,240 And so I negate is anything and when I put no now it will return me true. 113 00:07:02,720 --> 00:07:06,410 And when I put a screen now it will return me false. 114 00:07:06,800 --> 00:07:07,190 Right. 115 00:07:09,120 --> 00:07:14,490 So whenever I put here, it will return false if it's not a number, right? 116 00:07:15,000 --> 00:07:16,410 So that actually returned. 117 00:07:16,410 --> 00:07:24,930 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 118 00:07:25,230 --> 00:07:29,850 telling you some pressing SDF so we are not able to put a screen. 119 00:07:30,120 --> 00:07:30,510 Why? 120 00:07:30,510 --> 00:07:39,480 Because in the index I do have this type number and in that browser in Firefox or in Google Chrome, 121 00:07:39,480 --> 00:07:40,620 it is working like that. 122 00:07:40,620 --> 00:07:42,800 It's not allowing you to put a string here. 123 00:07:43,290 --> 00:07:46,200 That's one way you can make this application it. 124 00:07:46,500 --> 00:07:50,320 So it's not a number in what we can do here. 125 00:07:50,340 --> 00:07:55,590 We're going to say get for input, not calories. 126 00:07:55,590 --> 00:07:55,920 Right. 127 00:07:57,210 --> 00:07:59,680 So let's see if that will work. 128 00:07:59,840 --> 00:08:06,480 Now, just going to remove this one here and remove everything. 129 00:08:06,720 --> 00:08:08,880 And I'm just going to put a food here. 130 00:08:09,810 --> 00:08:10,980 I'm going to click enter. 131 00:08:11,490 --> 00:08:14,930 You have empty description, fill in. 132 00:08:14,970 --> 00:08:15,960 Why is this happening? 133 00:08:15,960 --> 00:08:20,660 Because here here I don't have this one now, 15. 134 00:08:22,170 --> 00:08:24,950 Now it will go any inside will enter. 135 00:08:25,080 --> 00:08:29,400 So I do have you have an empty description fill and I'm checking two things here. 136 00:08:29,550 --> 00:08:35,190 That's why to go there, because one of them was not was not a number was actually an empty string. 137 00:08:35,280 --> 00:08:39,950 So if I go back here, it will you have an empty so we can change it. 138 00:08:39,950 --> 00:08:41,880 You have an empty fields. 139 00:08:44,550 --> 00:08:51,690 Or make better, let the better do this so you can say, please feel the form correctly, but we're 140 00:08:51,690 --> 00:08:59,070 going to remove these Ellspermann, please feel the form correctly. 141 00:09:02,130 --> 00:09:08,730 Like that and make it A, B, C, so now it will not go there. 142 00:09:08,760 --> 00:09:12,570 Please fill in the form, collect correctly food in calories. 143 00:09:13,740 --> 00:09:14,450 How cool is this? 144 00:09:14,460 --> 00:09:15,320 They're working now. 145 00:09:15,330 --> 00:09:18,030 I need to check one more thing here. 146 00:09:18,250 --> 00:09:21,750 If I put a zero, it will still work. 147 00:09:21,750 --> 00:09:22,140 Right. 148 00:09:22,890 --> 00:09:25,280 And I don't want that to happen. 149 00:09:25,290 --> 00:09:34,830 So what I can do, I can check if the get for input calories is bigger than zero. 150 00:09:34,830 --> 00:09:35,140 Right. 151 00:09:35,310 --> 00:09:37,460 That will fix two things. 152 00:09:37,470 --> 00:09:42,660 It will fix the negative values that we can enter minus and it will fix if it's zero. 153 00:09:42,670 --> 00:09:46,470 So I'm just asking these value to be bigger and positive. 154 00:09:46,470 --> 00:09:46,780 Right. 155 00:09:47,280 --> 00:09:50,430 You know, I save food, click, enter. 156 00:09:50,430 --> 00:09:51,090 It's working. 157 00:09:51,270 --> 00:09:54,540 Let's try with minus should not work. 158 00:09:54,550 --> 00:09:56,130 Please fill in the form correctly. 159 00:09:56,280 --> 00:10:01,380 If we put a zero areas he's saying to here it's not working. 160 00:10:01,530 --> 00:10:04,350 OK, so we fix a couple of scenarios here. 161 00:10:04,350 --> 00:10:05,910 We need to do this one. 162 00:10:06,510 --> 00:10:06,930 Right. 163 00:10:07,530 --> 00:10:12,180 We're not worried about the selection because it's already been preselected. 164 00:10:12,750 --> 00:10:14,040 He's been selected to add. 165 00:10:14,040 --> 00:10:21,270 But if you have a preference to do the burn, just cut this part here and put it here and every time 166 00:10:21,270 --> 00:10:24,120 you will be selected the burn part. 167 00:10:24,960 --> 00:10:29,430 Now, one more thing we need to do, we need to check for. 168 00:10:29,700 --> 00:10:30,900 I'm just going to copy this one. 169 00:10:32,160 --> 00:10:39,870 I'm just going to copy even with that and operator so now get put quantity. 170 00:10:40,710 --> 00:10:43,470 OK, not should not I should not go there. 171 00:10:43,650 --> 00:10:44,670 So I should go here. 172 00:10:44,670 --> 00:10:45,330 Quantity. 173 00:10:47,910 --> 00:10:54,210 Better to make it like this, and quantity should be bigger than zero as well. 174 00:10:54,670 --> 00:10:57,180 OK, no, let's just it that when I click here. 175 00:10:57,210 --> 00:11:00,630 Please fill the form food again. 176 00:11:00,780 --> 00:11:01,730 It's not working. 177 00:11:01,980 --> 00:11:02,940 Just the calories. 178 00:11:03,360 --> 00:11:04,340 It's not working. 179 00:11:04,350 --> 00:11:07,170 Put here one and it will work. 180 00:11:07,200 --> 00:11:09,470 Now I do have like just test it out. 181 00:11:09,480 --> 00:11:11,550 If I put zero will not work. 182 00:11:11,760 --> 00:11:15,840 If I put minus one still it will not work. 183 00:11:16,080 --> 00:11:19,150 So now the form is super secure. 184 00:11:19,170 --> 00:11:20,510 I mean it's not secure. 185 00:11:20,700 --> 00:11:24,570 It doesn't allow us to to get input. 186 00:11:24,570 --> 00:11:26,820 That is not valid for our calculation. 187 00:11:26,850 --> 00:11:31,290 For example, I'm not being able to put minus 150 calories. 188 00:11:31,290 --> 00:11:31,590 Right. 189 00:11:31,980 --> 00:11:37,740 Because that means that I'm going to burn and I should select this and I should again put a positive 190 00:11:37,740 --> 00:11:43,760 number, because after that, we will subtract that number from this total here. 191 00:11:43,800 --> 00:11:44,160 Right. 192 00:11:44,730 --> 00:11:46,190 So that's pretty much it for this lecture. 193 00:11:46,200 --> 00:11:49,460 What we have done, I'm just going to be super, super quick. 194 00:11:50,880 --> 00:11:56,660 So we use Borislow and pass in to convert that string to an integer. 195 00:11:56,670 --> 00:11:58,170 That's why we have this now. 196 00:11:58,560 --> 00:12:01,530 A hundred and fifty and this also. 197 00:12:04,160 --> 00:12:12,200 The add calories where it is in the add calories, we did check in this function if the description 198 00:12:12,440 --> 00:12:16,180 is empty, if this is a number. 199 00:12:16,220 --> 00:12:20,150 So if it's not number eight, that's why this sign is here. 200 00:12:20,150 --> 00:12:26,750 Operator, otherwise, if it's greater than zero, so we get rid of that negative values and zeros and 201 00:12:26,750 --> 00:12:28,380 we have done the same thing for quantity. 202 00:12:28,640 --> 00:12:31,760 Now we can take care for the rest of the hour. 203 00:12:31,760 --> 00:12:35,150 Logic in that, do something with adding calories. 204 00:12:35,330 --> 00:12:36,790 So I hope you enjoyed this lecture. 205 00:12:37,100 --> 00:12:43,620 It wasn't something special, but we just still managed to do a couple of things that will make a bucks 206 00:12:43,640 --> 00:12:44,410 in future. 207 00:12:44,420 --> 00:12:46,490 We will have to do them in future. 208 00:12:46,500 --> 00:12:47,450 So thank you very much. 209 00:12:47,630 --> 00:12:49,560 And now we'll see you in the next one. 210 00:12:49,580 --> 00:12:54,320 Also, we're not going to use this one that was just for testing. 211 00:12:54,620 --> 00:12:56,660 You can comment out or you can delete that one. 212 00:12:56,660 --> 00:12:56,940 Right. 213 00:12:57,090 --> 00:13:01,110 So I'm just going to delete and maybe in future I'm going to show you something. 214 00:13:02,000 --> 00:13:06,380 For example, if you want to get here some message, you can write message. 215 00:13:06,380 --> 00:13:12,290 And after after we finish this project, you can put your div with a with a class message. 216 00:13:12,560 --> 00:13:16,160 And when the form is not good, you can just display that one. 217 00:13:16,250 --> 00:13:16,640 Right. 218 00:13:17,480 --> 00:13:25,010 Which you can select with a selector, but that is for your for you to do after we finish this project. 219 00:13:25,010 --> 00:13:25,280 Right. 220 00:13:25,490 --> 00:13:29,450 Because it's not going to be complex, because you can learn a lot of things and you will know how to 221 00:13:29,450 --> 00:13:29,800 do them. 222 00:13:29,990 --> 00:13:32,600 So thank you very much and I will see you in the next one.