1 00:00:00,580 --> 00:00:01,350 Welcome back. 2 00:00:01,360 --> 00:00:05,250 In today's lecture, we are going to work on lecture, seminar, exercise solutions. 3 00:00:05,530 --> 00:00:07,240 So why are we going to do this? 4 00:00:07,240 --> 00:00:09,300 Because this one is pretty much complex. 5 00:00:09,310 --> 00:00:16,340 It will involve arrays, objects, if conditions and logical operators. 6 00:00:16,340 --> 00:00:23,470 So if you know how to do this and if you have done it, then Mark this lecture is finished and move 7 00:00:23,470 --> 00:00:23,770 on. 8 00:00:24,040 --> 00:00:32,230 If not, just create here new file called Lecture seven Exercise Solutions and link the same one here 9 00:00:32,470 --> 00:00:33,640 in your index. 10 00:00:34,030 --> 00:00:34,410 Right. 11 00:00:34,690 --> 00:00:37,600 Because we need to check what is going to happen in the browser. 12 00:00:37,870 --> 00:00:45,670 Also make sure that from a final folder, just grab this exercise lecture seven exercise judges read 13 00:00:45,670 --> 00:00:46,510 the entire thing. 14 00:00:46,510 --> 00:00:48,340 I just copy this, the whole thing. 15 00:00:48,340 --> 00:00:49,120 And I put it here. 16 00:00:49,360 --> 00:00:49,740 Right. 17 00:00:50,320 --> 00:00:51,430 That's it now. 18 00:00:52,880 --> 00:00:53,120 And. 19 00:00:54,340 --> 00:00:55,600 Copy this for. 20 00:00:57,180 --> 00:01:05,430 Put them here and let's make them as a comment, don't create a variable array that will be empty and 21 00:01:05,430 --> 00:01:08,260 it will halt user objects in future. 22 00:01:08,280 --> 00:01:10,260 Very good variable database. 23 00:01:11,160 --> 00:01:19,380 Equal, an empty array, nice next one from the user to enter his name and store it in a very real username 24 00:01:19,770 --> 00:01:22,830 var user name and prompt. 25 00:01:24,400 --> 00:01:24,960 Very good. 26 00:01:24,970 --> 00:01:26,410 Now inside the prompt. 27 00:01:26,430 --> 00:01:27,450 We had one argument. 28 00:01:27,450 --> 00:01:30,630 Call your name nice. 29 00:01:31,020 --> 00:01:32,030 So copied. 30 00:01:32,040 --> 00:01:34,920 This one is going to be similar because oops. 31 00:01:35,520 --> 00:01:37,770 Because here we are prompting the user name. 32 00:01:38,010 --> 00:01:45,360 Use it to user to enter his user email in your email address. 33 00:01:45,630 --> 00:01:52,440 Now here will provide the user to get his passport and save it as a user password variable. 34 00:01:52,440 --> 00:01:52,750 Right. 35 00:01:53,310 --> 00:01:53,820 Nice. 36 00:01:55,740 --> 00:02:02,310 OK, comes along and see what we have, so council log, they use pirnie email. 37 00:02:02,910 --> 00:02:11,940 Let's start with the name user email and user password and let's see if we are going to get the right 38 00:02:11,940 --> 00:02:12,560 output. 39 00:02:12,780 --> 00:02:13,560 So your name? 40 00:02:13,560 --> 00:02:15,040 Rick Password. 41 00:02:15,450 --> 00:02:21,180 Email are at Gmail dot com and one, two, three, four. 42 00:02:21,180 --> 00:02:22,590 Password hit enter. 43 00:02:24,280 --> 00:02:25,910 And why don't have here? 44 00:02:27,140 --> 00:02:28,240 Hmm, strange. 45 00:02:29,620 --> 00:02:31,540 Save it again, sometimes this can happen. 46 00:02:33,110 --> 00:02:34,400 Did I linked it correctly? 47 00:02:34,430 --> 00:02:35,050 Yes, I did. 48 00:02:37,020 --> 00:02:37,860 Name, Rick. 49 00:02:40,340 --> 00:02:43,470 Email address are at Gmail dot com. 50 00:02:44,330 --> 00:02:49,990 You can put any email address 1-3 here it is now it's working, right? 51 00:02:50,030 --> 00:02:51,040 I didn't change anything. 52 00:02:51,050 --> 00:02:52,360 I need to receive it. 53 00:02:52,480 --> 00:02:52,920 Good. 54 00:02:53,240 --> 00:02:54,720 Now, what is number five? 55 00:02:54,950 --> 00:03:00,800 Number five is create a function called the register that will take three arguments from the prompt. 56 00:03:01,040 --> 00:03:04,250 So function oops register. 57 00:03:04,250 --> 00:03:05,510 That will take three arguments. 58 00:03:05,690 --> 00:03:08,960 It will be name, email and password. 59 00:03:09,350 --> 00:03:10,130 Very good. 60 00:03:10,340 --> 00:03:13,540 Now this function, what it needs to do. 61 00:03:15,770 --> 00:03:16,550 Very good. 62 00:03:16,850 --> 00:03:23,780 Let me just do it like this field, the database with a user object that will contain the three fields. 63 00:03:23,780 --> 00:03:24,400 Nice. 64 00:03:25,430 --> 00:03:31,520 So we need to create an object in our database array. 65 00:03:31,700 --> 00:03:36,490 So how are we going to do this database that push it inside? 66 00:03:36,500 --> 00:03:37,840 We're going to create an object. 67 00:03:38,150 --> 00:03:38,760 Very good. 68 00:03:38,900 --> 00:03:47,060 So name it will be the name that is coming from our arguments then comma. 69 00:03:47,270 --> 00:03:49,940 We will have email that will come from email. 70 00:03:50,660 --> 00:03:51,100 Very good. 71 00:03:51,110 --> 00:03:52,880 And you can name this whatever you want. 72 00:03:53,420 --> 00:03:55,730 And we want to have a password. 73 00:03:56,420 --> 00:04:03,680 Now this will be the field name inside the object right in the past is coming from the function that 74 00:04:03,680 --> 00:04:04,460 we're going to pass. 75 00:04:04,490 --> 00:04:04,880 Nice. 76 00:04:05,690 --> 00:04:06,070 Oops. 77 00:04:07,580 --> 00:04:15,590 Here needs to go semicolon now, call the register, function, the prompt, whatever we stored here, 78 00:04:15,590 --> 00:04:15,950 write. 79 00:04:17,540 --> 00:04:24,080 And we know that they're working because we check them, we can lock them like a minute ago, the email 80 00:04:24,230 --> 00:04:26,000 and user password. 81 00:04:26,900 --> 00:04:27,680 Very good. 82 00:04:27,830 --> 00:04:28,430 Save it. 83 00:04:28,640 --> 00:04:29,900 Save a couple of times. 84 00:04:30,950 --> 00:04:33,410 Refresh it here on what's happening. 85 00:04:35,680 --> 00:04:42,490 Your name, Rick, very good, are sick Gmail dot com. 86 00:04:43,820 --> 00:04:47,150 OK, one, two, three, four, three, doesn't matter. 87 00:04:47,540 --> 00:04:48,800 Let's check the database. 88 00:04:50,030 --> 00:04:50,610 Mm hmm. 89 00:04:50,840 --> 00:04:54,720 I do see that some object is created and there you go. 90 00:04:54,980 --> 00:04:58,440 We do have our first object stored in a database array. 91 00:04:58,740 --> 00:04:59,950 Congratulations. 92 00:05:00,260 --> 00:05:08,780 So let me just do this console like I hate with this out of complete control, the lock, the database 93 00:05:09,410 --> 00:05:10,010 array. 94 00:05:10,070 --> 00:05:14,240 Now, I don't need to type it here all of the time. 95 00:05:14,270 --> 00:05:20,110 OK, now what we are going to do is we are going to move on. 96 00:05:20,240 --> 00:05:24,170 So six is done, seven canceling the prom and see what will happen. 97 00:05:24,410 --> 00:05:27,320 Do you get database with null or empty values? 98 00:05:27,330 --> 00:05:28,640 How we can fix this. 99 00:05:29,030 --> 00:05:29,530 Nice. 100 00:05:30,290 --> 00:05:32,600 So let's cancel the proms. 101 00:05:33,350 --> 00:05:34,010 Cancel. 102 00:05:34,790 --> 00:05:35,450 Cancel. 103 00:05:37,060 --> 00:05:44,380 Here is I do have an array with no object that is crazy, right? 104 00:05:44,650 --> 00:05:45,220 Why? 105 00:05:45,760 --> 00:05:52,690 Because this function was called and doesn't matter what was inside here, it was nothing, actually. 106 00:05:52,990 --> 00:05:56,470 And it was called with the with those empty values. 107 00:05:56,740 --> 00:06:01,650 And we pushed into the database, all of those things. 108 00:06:01,990 --> 00:06:03,580 So now we need to fix it. 109 00:06:03,580 --> 00:06:04,500 How are we going to fix it? 110 00:06:04,810 --> 00:06:11,520 So I'm going to do like this seven, eight and nine. 111 00:06:12,010 --> 00:06:13,570 We are going to do in one go. 112 00:06:13,570 --> 00:06:20,770 So we're going to do if conditions with this condition, we're going to check if the user name is different, 113 00:06:20,770 --> 00:06:23,890 then no, very good. 114 00:06:24,190 --> 00:06:36,370 And we need to use the logical operator end user email is going to be different then no end user password 115 00:06:36,490 --> 00:06:37,300 needs to be. 116 00:06:38,280 --> 00:06:45,900 Different than no, very good what this means that I want each and every of these variables to have 117 00:06:45,900 --> 00:06:46,590 some data. 118 00:06:46,770 --> 00:06:55,750 That's why these and otherwise, if you put or hear the pipe then means that these two needs to be filled. 119 00:06:55,770 --> 00:06:56,910 And this one not in. 120 00:06:56,910 --> 00:06:58,200 That is not what we want. 121 00:06:58,530 --> 00:07:00,600 So here it will go. 122 00:07:01,260 --> 00:07:03,630 Only if this contains data. 123 00:07:04,470 --> 00:07:11,310 And if not, we're going to have this condition and we're going to alert the user and say some of the 124 00:07:11,310 --> 00:07:13,050 form fields. 125 00:07:13,050 --> 00:07:17,030 Actually, we don't have form, but let's do it are empty. 126 00:07:18,900 --> 00:07:22,650 Please try again. 127 00:07:23,100 --> 00:07:23,790 Very good. 128 00:07:25,410 --> 00:07:28,200 Now, here the logic goes like this. 129 00:07:28,650 --> 00:07:33,930 Any time we're going to call this register function is only when these variables hold any meaningful 130 00:07:33,930 --> 00:07:36,130 data, they will not be known. 131 00:07:36,480 --> 00:07:44,420 Right now, let's hit it here, refresh it and cancel everything first. 132 00:07:44,790 --> 00:07:45,330 Here it is. 133 00:07:45,330 --> 00:07:46,940 Some of the fields are empty. 134 00:07:46,950 --> 00:07:48,270 Please try it again. 135 00:07:50,700 --> 00:07:51,060 Yeah. 136 00:07:51,930 --> 00:07:57,660 You need to clear a couple of times, probably now our alert is working because we were trying to register 137 00:07:57,870 --> 00:08:04,260 and now the database, if we try to access that database, it will not work because this alert is there. 138 00:08:04,440 --> 00:08:04,810 Right? 139 00:08:05,970 --> 00:08:07,410 That database is empty. 140 00:08:08,250 --> 00:08:21,500 OK, now let's do a real Rick or am Gmail dot com and very good. 141 00:08:22,620 --> 00:08:24,030 We have a database. 142 00:08:24,150 --> 00:08:26,790 Get our M Gmail dot com. 143 00:08:26,790 --> 00:08:27,720 One, two, three, four. 144 00:08:27,750 --> 00:08:28,110 Nice. 145 00:08:29,250 --> 00:08:35,040 So that is pretty much what we want to do in the six, seven and eight. 146 00:08:36,330 --> 00:08:40,380 In nine, actually, they put it like that, six, seven, eight, nine. 147 00:08:41,070 --> 00:08:43,220 So how we can fix it, we already fix it. 148 00:08:43,230 --> 00:08:45,900 Try saving the database user objects only when. 149 00:08:46,110 --> 00:08:47,790 Yeah, this was number 10 as well. 150 00:08:48,300 --> 00:08:50,430 Oh, we have covered a lot. 151 00:08:51,290 --> 00:08:54,630 Now check if the name of the user object. 152 00:08:55,830 --> 00:08:57,410 So the name of this object. 153 00:08:57,660 --> 00:08:59,580 So if it's righ right. 154 00:09:01,870 --> 00:09:08,020 An object in a database is the same with the name of the user name that we got from the prompt in here 155 00:09:08,320 --> 00:09:08,920 from. 156 00:09:10,570 --> 00:09:14,420 Guess if he has done this play, welcome to the profile page, dear. 157 00:09:14,560 --> 00:09:15,550 Name of the user. 158 00:09:15,650 --> 00:09:16,040 Nice. 159 00:09:16,240 --> 00:09:18,610 So that will be another issue here if. 160 00:09:19,780 --> 00:09:20,470 Databased. 161 00:09:22,160 --> 00:09:26,570 So how many actually, let me just write down, because I refresh it, Rick. 162 00:09:28,450 --> 00:09:32,380 Email our Gmail dot com. 163 00:09:34,100 --> 00:09:34,880 Onto three. 164 00:09:35,840 --> 00:09:42,630 I get now in our database, we always going to have only one registered user, and why is this? 165 00:09:42,810 --> 00:09:49,380 Well, because when they save it and a refresh and the compiler gets to this line and it sent the database 166 00:09:49,530 --> 00:09:50,880 back to empty, that's why. 167 00:09:51,090 --> 00:09:53,160 OK, so the database of zero. 168 00:09:55,090 --> 00:10:00,850 And I want to access the name, that name is equal equal to what? 169 00:10:01,300 --> 00:10:02,820 The username variable. 170 00:10:03,130 --> 00:10:07,320 So whatever this variable holds, it needs to be the same with this one. 171 00:10:07,330 --> 00:10:12,950 If that is the case, then what we need to do is saying cancel that log. 172 00:10:13,780 --> 00:10:19,750 Welcome to your profile page, dear. 173 00:10:21,110 --> 00:10:23,240 Make a breathing space username. 174 00:10:25,270 --> 00:10:29,820 And else, let's put alert here. 175 00:10:32,360 --> 00:10:33,200 Something. 176 00:10:34,500 --> 00:10:36,010 Went wrong. 177 00:10:37,530 --> 00:10:40,580 Please try again later. 178 00:10:43,280 --> 00:10:44,500 And that's pretty much it. 179 00:10:47,510 --> 00:10:49,040 So we hear, Rick. 180 00:10:51,000 --> 00:10:54,420 Email break at Hotmail dot com. 181 00:10:55,760 --> 00:10:56,450 Very good. 182 00:10:59,060 --> 00:11:00,950 Welcome to your profile page, d'Afrique. 183 00:11:01,340 --> 00:11:07,420 Everything is working, our database array holds one object crazy. 184 00:11:08,270 --> 00:11:09,440 Now congratulations. 185 00:11:09,740 --> 00:11:12,230 You know how to do it fails conditions. 186 00:11:12,440 --> 00:11:18,800 You know now how to push through the database on object and now you know how to deal with objects. 187 00:11:18,800 --> 00:11:19,340 Crazy. 188 00:11:19,520 --> 00:11:20,710 That is super. 189 00:11:20,960 --> 00:11:24,200 I really enjoy having you as my student. 190 00:11:24,200 --> 00:11:28,030 If you are here, that means that you're doing something great. 191 00:11:28,040 --> 00:11:30,380 So I will see you in the next one. 192 00:11:30,380 --> 00:11:33,080 And don't get don't get scared. 193 00:11:33,080 --> 00:11:35,480 It will get better in time. 194 00:11:35,480 --> 00:11:39,560 So just please practice and let's fix this problem here. 195 00:11:39,560 --> 00:11:42,020 Email right now. 196 00:11:42,210 --> 00:11:46,370 So, yeah, I'm sorry if I see some mistake here. 197 00:11:46,490 --> 00:11:48,260 I mean this. 198 00:11:49,420 --> 00:11:54,450 Language mistake and yeah, we'll try to fix it in the final solutions folder, right. 199 00:11:54,480 --> 00:11:55,660 So see you in the next one. 200 00:11:55,690 --> 00:11:57,280 And stay safe, but.