YouTube2Text

Lets build 4 javascript projects for beginners | chai aur #javascript — Transcript

by Chai aur Code · 18,181 words · 2,503 segments · language en · Watch on YouTube

Full transcript

  1. 0:00Yes, how are you all? Welcome to Chai
  2. 0:03Aur Code, and we're running our series,
  3. 0:05which we've renamed Chai Aur JavaScript
  4. 0:08. Look, I don't think there could be a
  5. 0:09better name than this. Let me know in
  6. 0:12the comments how you liked this new
  7. 0:13name, Chai Aur JavaScript. Similarly,
  8. 0:15we've already done Chai Aur HTML, and
  9. 0:17we'll be doing more soon. But for now,
  10. 0:20our main focus of this video is your
  11. 0:22favorite projects. Yes, I know a lot of
  12. 0:25people are excited about projects. But
  13. 0:28it's not like we can do high-level,
  14. 0:30high-end projects right away. Because
  15. 0:32we've only studied the basics. We've
  16. 0:34finished the basics, and we've finished
  17. 0:35intermediate. We've studied a little
  18. 0:37bit. But as I always say, you won't be
  19. 0:38able to do full-fledged projects after
  20. 0:40studying just this much. But that's not
  21. 0:42the case. In this video, I'll share a
  22. 0:44very exciting project: projects you've
  23. 0:46never done before—in a course, a paid
  24. 0:49course, or a boot camp. You've likely
  25. 0:51never had an experience like the one
  26. 0:53I'm going to give you for free on this
  27. 0:55channel, with projects. Yes, I have
  28. 0:57some expertise, having written code for
  29. 0:5910-12 years, so I'll have to share that
  30. 1:01experience. That's it. Look, we're less
  31. 1:04noisy here and more practical. So we
  32. 1:07won't make a big fuss about something
  33. 1:10terrible. But yes, we've done a great
  34. 1:12job, which will make your project
  35. 1:13journey much better. Your project
  36. 1:15practice will increase, and you'll be
  37. 1:17able to practice multiple times without
  38. 1:19worry. Just open your browser and
  39. 1:21you'll be able to do many projects. Now
  40. 1:23, we won't be able to do many projects
  41. 1:25because we haven't discussed events yet
  42. 1:27. We'll need one or two long videos
  43. 1:30about events, in which we'll understand
  44. 1:32events: how events work in JavaScript,
  45. 1:35what they do, what types of events
  46. 1:37exist, how to use them, and how to
  47. 1:39delve deeper into them. And without
  48. 1:41events, it's actually impossible to do
  49. 1:43many projects without DOM. In fact,
  50. 1:45it's impossible to do any project at
  51. 1:46all. So, during this project, this long
  52. 1:49video, I'll be giving you some tips and
  53. 1:52hints about how events are happening.
  54. 1:54But please assume that if anyone asks
  55. 1:56in the comments that I didn't explain
  56. 1:57this or that, please tell them, "Oh, I
  57. 1:59don't have the patience. How can I
  58. 2:01become a programmer?" Right now, we're
  59. 2:02just studying the basics of events.
  60. 2:04Just enough to do the projects. But
  61. 2:07after that, we'll delve into events in
  62. 2:09depth. Okay? So now let's talk about
  63. 2:12our projects. How many projects are we
  64. 2:13going to do? We're going to do four
  65. 2:15projects in this one video. And with
  66. 2:17great difficulty, I've set up projects
  67. 2:19that gradually increase in complexity
  68. 2:21so that you gain confidence, because
  69. 2:23this series has one main motive: to
  70. 2:25build confidence that you can write
  71. 2:27code. Okay? So now I'll show you how
  72. 2:29much hard work we've put in here. Not
  73. 2:31only that, but I've done it myself,
  74. 2:33because I don't have a team on this
  75. 2:34channel. Everything has to be done by
  76. 2:36myself. So let me tell you what I
  77. 2:39actually did here. First, I went to
  78. 2:41Code Sandbox. If you're unfamiliar with
  79. 2:43Code Sandbox, it's a great website.
  80. 2:45What happens here? You can create
  81. 2:46templates for JavaScript and other
  82. 2:48similar things so people can practice
  83. 2:49them in the browser, or you can write
  84. 2:51the entire code in the browser. As
  85. 2:53we've done throughout the series, I was
  86. 2:54writing the entire code here inside
  87. 2:56GetUp. I was writing it in the browser.
  88. 2:58What I did now was use Code Sandbox,
  89. 3:00which I always do. I have a lot of old
  90. 3:02projects that I give to people for
  91. 3:03practice. I'll give them to you too.
  92. 3:05Don't worry. I encountered a few minor
  93. 3:07problems there. The platform is good.
  94. 3:09No problems. But I encountered some
  95. 3:11minor issues there, and I thought I'd
  96. 3:13be able to work through them with
  97. 3:15practice. So, I didn't complete the
  98. 3:17project. I then moved the project to
  99. 3:20another website called Stock Blades.
  100. 3:22Now, what's inside the Stock Blades
  101. 3:23website? I created these DOM projects,
  102. 3:25and this is how you'll see them when
  103. 3:27you open them. Now, since I've created
  104. 3:30an account and created all the code
  105. 3:32here, any changes I make will be saved.
  106. 3:35I don't want to save those changes. I'm
  107. 3:37not going to give you the code file.
  108. 3:40But what I want is an experience where
  109. 3:42you don't have to worry about creating
  110. 3:44any installation files. You can simply
  111. 3:47go ahead and write JavaScript code,
  112. 3:48practice the code, and complete the
  113. 3:50project. This is the experience I
  114. 3:52wanted everyone to have. Now, it took
  115. 3:54some time to create this experience, so
  116. 3:56I've made you wait a little while. But
  117. 3:58now, since I've created the project
  118. 4:00here, I can share this project with you
  119. 4:03. And I'll share it with you. I want
  120. 4:06your index file to be there by default,
  121. 4:08and I'll copy it here. I'm sharing this
  122. 4:10so you can see behind the scenes of how
  123. 4:12much work was done here and how you're
  124. 4:13getting the project. If I gave you a
  125. 4:16direct, magical link, you'd say, "Yes,
  126. 4:17everything is working." But you should
  127. 4:19also know the behind-the-scenes of how
  128. 4:20the labs were created. What services
  129. 4:22did I use, how did I get help, what all
  130. 4:24happened? So I copied the URL. Okay?
  131. 4:28Now, one thing you should keep in mind
  132. 4:29here. What some people do is open a new
  133. 4:31incognito tab and paste it there. You
  134. 4:34can do that. No problem. The FIR will
  135. 4:35be created there too. But what happens
  136. 4:37there? You won't see any code preview
  137. 4:40on the right-hand side. Okay? So please
  138. 4:43don't open it in incognito mode. Open
  139. 4:45it in your regular browser because I'm
  140. 4:47already logged in. Anything I save will
  141. 4:49be saved. Then how will you practice?
  142. 4:52So what's the point? I'm opening a
  143. 4:53Safari browser here. You can use any
  144. 4:56browser, Chrome, anything; it won't
  145. 4:58matter. The problem is because I'm
  146. 5:00locked in. Now, you won't have my code
  147. 5:02files, so you're not locked in, it
  148. 5:04won't matter. So, I opened this same
  149. 5:07URL here. Now, what's the point of this
  150. 5:10URL? Suppose I wrote it here. I wrote
  151. 5:13it all. Okay? Now, I wrote it, but
  152. 5:15suppose I want to go to Project One, so
  153. 5:17I'll click here and say, okay, this is
  154. 5:19Project One. I want to create this
  155. 5:21color switcher, and I can go back to
  156. 5:22home. The link to the YouTube channel
  157. 5:24is there, obviously. But suppose, for
  158. 5:26some reason or by mistake, you deleted
  159. 5:28all the links. So, here they are, the
  160. 5:30links are deleted. So what happens now?
  161. 5:33No problem. If all the links are
  162. 5:35deleted, just refresh this page and say
  163. 5:37, "Yes, leave this page." Refresh it,
  164. 5:40and you'll have the exact code, what we
  165. 5:43call starter code, so you can focus on
  166. 5:45it without any worries. But if you want
  167. 5:49to save any changes you're making, like
  168. 5:51whatever JavaScript I'm writing, then
  169. 5:53click on the "difference" button. What
  170. 5:56will that do? The entire project will
  171. 5:57be uploaded to your Stag Blitz. Yes,
  172. 5:59you'll have to create a Stuckets
  173. 6:00account. I don't have any sponsorship
  174. 6:02from Stuckets or Code Sandbox. In fact,
  175. 6:05I purchased Code Sandbox, so I didn't
  176. 6:07take any sponsorship from my own money.
  177. 6:09So, if you want, click "fork" here, and
  178. 6:11it will say that the project has been
  179. 6:13forked. Now, any changes you make will
  180. 6:15be saved, but you'll need to sign in.
  181. 6:17It won't save without signing in. Okay?
  182. 6:20So, the second thing is, where will you
  183. 6:22get this link? You'll find this link in
  184. 6:24your code file. So, what do we do here?
  185. 6:28Simply create a Markdown file. And
  186. 6:30through that Markdown file, I'll take
  187. 6:32you all the links here. So, let's
  188. 6:34create a new folder and name it 07 "and
  189. 6:39" projects. Here, inside this 07
  190. 6:42projects, we'll create a new file
  191. 6:45called projects. A set "one .dot" md.
  192. 6:53An md is a Markdown file. We won't
  193. 6:56discuss much about the Markdown file
  194. 7:00right now. Yes, we won't discuss much
  195. 7:03about our Markdown file, what it does,
  196. 7:05how it works, why it works. But you'll
  197. 7:08see a little button above. This button
  198. 7:10opens a preview for your Markdown. By
  199. 7:13the way, I've made a nice detailed
  200. 7:14video about Markdown on my English
  201. 7:16channel. If you request it, please
  202. 7:17leave a request in the comments section
  203. 7:18. I should get a lot of requests. Then
  204. 7:21I'll upload a Hindi Markdown video here
  205. 7:23as well. So, we've opened the preview
  206. 7:24of this Markdown. Now, what can we do
  207. 7:26here? Just put a hash and say "Projects
  208. 7:31Related to Markdown." Okay? Now, I need
  209. 7:37to write the project link here. So,
  210. 7:38I'll write the project link here as
  211. 7:40well. How do I place the project link
  212. 7:42and the project link here? Here we go.
  213. 7:47This is our project link. And let's
  214. 7:50name it "Click Here." So, anyone who
  215. 7:56sees the preview just needs to click
  216. 7:57here, and anyone who doesn't want to do
  217. 7:59it can copy and paste it from the code
  218. 8:00file here. Now, you have the project
  219. 8:02file. Now, not just that, what else can
  220. 8:05we do here? I'll also give you the code
  221. 8:07for the projects a little bit more so
  222. 8:08you can see the final solution code. So
  223. 8:11, here I'll write "Solution Code" and
  224. 8:16here comes "Solution Code." So, there
  225. 8:20you have the solution code. And here
  226. 8:22we'll write "Project One." Here we go,
  227. 8:27Project One. Now, here I have to write
  228. 8:29JavaScript code. So, I'll put three
  229. 8:31backticks, then I'll write "j vascript
  230. 8:34javascript" and these three backticks
  231. 8:37to end. Now, whatever code I write here
  232. 8:40, for example, let's say I write "
  233. 8:42console.log" here, and here we write "
  234. 8:45Hitesh." Here you go. So, you'll see
  235. 8:48that code here. If you look at the
  236. 8:50Markdown preview, we can copy and paste
  237. 8:52it from here. So, whatever solution we
  238. 8:54create for Project One, we can easily
  239. 8:56find it here. Okay? Got it? I'll even
  240. 9:00push it so you can all see it. So,
  241. 9:02we'll repeat the same steps: solution
  242. 9:04code for Project One, solution code for
  243. 9:06Project Two, and so on. But the best
  244. 9:08part is that we need to go to Safari
  245. 9:10now. Here's our Safari, and we just
  246. 9:12need to focus on completing these
  247. 9:14projects. The video will obviously be a
  248. 9:16little longer because we're working on
  249. 9:18four projects simultaneously, with the
  250. 9:19final one requiring a lot of work. So,
  251. 9:21please maintain some patience. Since
  252. 9:22you've been requesting me to make long
  253. 9:24videos for so many series, I think
  254. 9:25you've developed patience. You'll have
  255. 9:27a lot of fun, and you'll find it very
  256. 9:29interesting. Okay? So, let's close this
  257. 9:32. You can also go into Zen mode. See,
  258. 9:34when you go into Zen mode, you'll only
  259. 9:36see the code. I really like it when
  260. 9:37it's visible. I'll exit it now because
  261. 9:39I also need to insert myself into the
  262. 9:41video, so a small little bit at the
  263. 9:43bottom looks fine. Okay? So, what do we
  264. 9:46do now? First, let's delve into our
  265. 9:48color changer. Let's discuss this
  266. 9:50project. So, look, the color changer is
  267. 9:52a theme switcher, a project called
  268. 9:54Color Switcher Curry. It's created in
  269. 9:56many places. It's used in almost every
  270. 9:58course. So, we'll do it too. Obviously,
  271. 10:01the goal is simply to click on this,
  272. 10:03click on this, click on this, click on
  273. 10:05this. The entire background color
  274. 10:07should change. That's all it takes. Now
  275. 10:10, look, we know how to change the color
  276. 10:11because inside the DOM, we'll add a
  277. 10:13style and color inside the body. Okay?
  278. 10:16No problem. But how to solve it here is
  279. 10:18the biggest challenge. Because in a
  280. 10:20project, only what you've learned will
  281. 10:22appear. Remember, this isn't your 12th
  282. 10:23grade education, where only what you've
  283. 10:25learned will appear. A little more
  284. 10:26detail is also involved here. We also
  285. 10:28go into a little more detail in the
  286. 10:29project. So, look, these are our
  287. 10:31buttons. Okay, sir? Now, what happens
  288. 10:33with this? It seems to be an event. We
  289. 10:34haven't talked much about events yet,
  290. 10:35and we won't do that either. We'll talk
  291. 10:37about it in a separate video. Now,
  292. 10:39let's try to solve this project so you
  293. 10:42can understand it. So, what's the
  294. 10:43project? First, open the HTML. So,
  295. 10:45here's the HTML. Zoom in a little bit.
  296. 10:49Oh, and then I'll open the settings
  297. 10:53here. My settings are open. Ah, project
  298. 10:58settings here, and workspace settings.
  299. 11:03Here, I'll search for fonts. Font size.
  300. 11:10Yes, sir. Here's the font size. So,
  301. 11:12I'll make it a little bigger so you can
  302. 11:14see it better. Let's make it 20. Yes,
  303. 11:17sir. Now you'll see the font clearly.
  304. 11:19Let's save the settings. Since I'm in
  305. 11:22Safari, you won't see any changes I'm
  306. 11:24making. But I'll make the changes
  307. 11:26inside it so you can see the font
  308. 11:27clearly. Okay? So, let's go back inside
  309. 11:29. Now let's look at the index. You
  310. 11:31should be able to see it clearly now.
  311. 11:33We'll move it to the side because it's
  312. 11:34not needed that much. Even if it's
  313. 11:35smaller, it'll do. It's not that
  314. 11:37problematic. I was writing some styling
  315. 11:39and such. So I'll clean up this code.
  316. 11:41Don't worry about that. I've cleaned it
  317. 11:43up further. Now let's come back here.
  318. 11:45Okay? So the main thing right now is
  319. 11:46that we have this color switcher. This
  320. 11:48is a span. Inside it, we have these
  321. 11:50buttons, classes, and each one has an
  322. 11:52ID. Gray, White, Blue, Yellow. So,
  323. 11:55these are the four IDs we have. We've
  324. 11:57specifically assigned IDs accordingly
  325. 11:59so we can change the color based on
  326. 12:00them. If you want to add more, you can
  327. 12:02add more. Along with that, we also have
  328. 12:04CSS, which you don't need to worry
  329. 12:06about. We're not focusing on CSS right
  330. 12:08now. And we have a script called tea
  331. 12:09and code. This will be the script, and
  332. 12:11which one will it be? So if you look at
  333. 12:13the code, we don't have anything right
  334. 12:14now. It's completely empty. So how do
  335. 12:17we achieve this goal? First, we need to
  336. 12:21select the elements. Which elements? We
  337. 12:23need to select all the buttons. Okay?
  338. 12:26What do we need to do next? We need to
  339. 12:27select the body. Obviously, our goal is
  340. 12:29to change the color of the body. So, we
  341. 12:31see two elements here. One is the body.
  342. 12:33So how do we select the body?
  343. 12:35document.query.sector.body. Okay? The
  344. 12:37body is selected here. Or you can also
  345. 12:39select the document body. That's fine
  346. 12:40too. And we need to select all these
  347. 12:43buttons. Now, you can select by class
  348. 12:45or select by ID and hold down each
  349. 12:46button one by one. So, it's better to
  350. 12:49select them all at once. Why? So I can
  351. 12:52loop through this later. Obviously, we
  352. 12:54need to do it the easy way. So, using a
  353. 12:56loop seems easier to me. Okay? So,
  354. 12:58let's move on to our code. So, what do
  355. 13:01we do first? Let's get the buttons. Now
  356. 13:02, how do we get the buttons? To get the
  357. 13:04buttons, I first need a document, and
  358. 13:06inside it, I can write "dot query
  359. 13:08sector." Should I use "query sector" or
  360. 13:10"query sector all"? We need to select
  361. 13:12buttons. We need to select all. So,
  362. 13:13here's "query sector all." Now, what do
  363. 13:16we need to write inside it? We need to
  364. 13:17write "all buttons." So, dot buttons.
  365. 13:20Okay? Are these buttons or buttons?
  366. 13:21Let's check that once. Look, here we
  367. 13:24have buttons. Okay? That's all done.
  368. 13:26Now we have all the buttons. So, let's
  369. 13:29hold it in a variable. So, take this
  370. 13:31cost and call it "buttons." Here you go
  371. 13:35. If you want, you can even lock the
  372. 13:37console, saying, "Let's lock the
  373. 13:39console." A shortcut won't work here.
  374. 13:42console.log and tell it to print these
  375. 13:46buttons. Here, you'll see a small
  376. 13:49console at the bottom. So, look, we
  377. 13:51have a node list. We've also studied
  378. 13:53the node list prototype. It's not shown
  379. 13:55in as much detail here, but we've
  380. 13:56already studied it. So, we know how it
  381. 13:58works now. Okay? So, that's the basics.
  382. 14:01We don't need this console lock anymore
  383. 14:02. Let's remove it. Now, what do we need
  384. 14:05? We also need a body. Okay? So, we
  385. 14:07wrote const body because we need to
  386. 14:09hold it in a variable. How do we get
  387. 14:11the body? There are many ways to select
  388. 14:13the body. What will we do? Let's use
  389. 14:15the document.query field. And directly
  390. 14:17inside the query field, we'll provide
  391. 14:18the tag name. What tag name do we have?
  392. 14:20Body. Okay? So, we have the body, and
  393. 14:23we have the buttons. We've learned this
  394. 14:25much about the DOM. Okay? But now, can
  395. 14:28I also loop over the buttons? Yes, I
  396. 14:30certainly can. But we haven't studied
  397. 14:33events much. We'll briefly explore how
  398. 14:35events work. So, what are events? There
  399. 14:37are many events within the browser.
  400. 14:39Moving the cursor in the browser is an
  401. 14:41event. Closing a tab is also an event.
  402. 14:44Clicking somewhere is also an event. So
  403. 14:46, there are many events. We'll learn
  404. 14:48more about events. For now, our goal is
  405. 14:50simply to capture the event you click
  406. 14:53and perform certain actions with it. As
  407. 14:56we'll see, you'll start to understand
  408. 14:57once you do a project. It's not that
  409. 15:00complicated, and since I'm here, it's
  410. 15:01bound to be easy. Okay? So, we've got
  411. 15:03buttons, okay. Here are the buttons.
  412. 15:06Now, we know that we've got a node list
  413. 15:07. We've got a node list, not an HTML
  414. 15:09collection, so I know I can use a for
  415. 15:11each with it. Okay? You already know
  416. 15:13that much. It's even suggested that you
  417. 15:15could put it on a list. Okay, sir? I've
  418. 15:17put this for each. Now, inside the for
  419. 15:19each, I know I can write a callback.
  420. 15:21You can write an arrow function, a
  421. 15:23regular function, whatever you want.
  422. 15:26Here, I've written the function. And
  423. 15:28what's inside this function? Each one,
  424. 15:30because it's a for each loop, you'll
  425. 15:32find each button there. So, here, I'll
  426. 15:35call it button. Okay? Now, I've got
  427. 15:37this button, and I'm going to console
  428. 15:40lock it first, just for clarity.
  429. 15:42console.log. And let's see what we
  430. 15:45actually get inside the button. Here,
  431. 15:48we've printed the button. Let's look at
  432. 15:50the console log. So, you have the
  433. 15:51entire button, which is a complete HTML
  434. 15:53span, and you've got all the attributes
  435. 15:55inside it. You've got the tag name.
  436. 15:57You've got the inner HTML. I've got all
  437. 15:59the attributes, what are they? I've got
  438. 16:01the class. I've got the ID. So, at
  439. 16:03least I get all the elements of that
  440. 16:05button here. Okay? That much is clear.
  441. 16:08Now what do we do here? We'll do a
  442. 16:11little work here. We'll add an event
  443. 16:13listener to each of these buttons. Now,
  444. 16:15why would we add an event listener?
  445. 16:17Because, we know events happen inside
  446. 16:18the browser, but we also need someone
  447. 16:20to listen to them. Imagine if someone
  448. 16:22is standing alone and speaking
  449. 16:23something, and no one is listening to
  450. 16:25him, how long will he keep speaking?
  451. 16:27For example, if I'm teaching you on
  452. 16:29this channel, and no one is watching or
  453. 16:31sharing the videos, or subscribing, how
  454. 16:33long will I keep speaking? I'll think,
  455. 16:35okay, no one is listening, so stop this
  456. 16:37video series. Focus elsewhere, on our
  457. 16:39main channel, where 800,000 people are
  458. 16:41listening. But no, I know you're
  459. 16:43listening, you're subscribing. So, we
  460. 16:45need to look at events here too. So,
  461. 16:48how do we add events? You can add
  462. 16:50events anywhere. How do we do it?
  463. 16:51Suppose this is an individual button.
  464. 16:53If you loop it, it will be applied to
  465. 16:54all of them. You can simply add this
  466. 16:57method to it to add an event listener.
  467. 16:59Okay? Did you see? It's very simple,
  468. 17:01you add an event listener. Event
  469. 17:03listener means I'll listen to every
  470. 17:05event that happens here. But I don't
  471. 17:06want to listen to all events. The mouse
  472. 17:08hovers over it, the page refreshes, the
  473. 17:10page loads. There are many types of
  474. 17:12events. We'll discuss them later. So, I
  475. 17:14don't want to listen to all events. I
  476. 17:15want to listen to the click event. Okay
  477. 17:17? You can also listen to the mouse over
  478. 17:18if you want. So, you write click here.
  479. 17:21Okay? You've heard the click event. But
  480. 17:23what if there's a click event? Yes,
  481. 17:25that's great. So what do you do? Write
  482. 17:27a callback here. Here's the function,
  483. 17:30and here's the callback. Okay? So the
  484. 17:32event is done. Now we've called it. But
  485. 17:35what happens next? Whenever an event
  486. 17:37occurs, you have to carry that event
  487. 17:38along. That event object contains a lot
  488. 17:41of details. I'll explain what you find
  489. 17:44in those details later. For now, just
  490. 17:47name it 'e'. Now, look, this is just a
  491. 17:49name. You name it 'e'. Some people call
  492. 17:50it 'event'. Some people might call it '
  493. 17:53superman'. Some people might call it '
  494. 17:55tea'. Name it whatever you want. It's
  495. 17:58actually the event object itself. Okay?
  496. 18:00So, don't worry about variable names.
  497. 18:01So what do I do here? I'll name it 'e'.
  498. 18:05It'll be short, it'll be easy. Okay,
  499. 18:07sir. I've named it 'e'. Now, what do we
  500. 18:09do next? First, let's do a console log.
  501. 18:12Okay? console log console dot log,
  502. 18:16because only the console log will tell
  503. 18:17you what to do. Let's create this event
  504. 18:20and another one, e dot target. Okay? I
  505. 18:23want to create it on both of them so I
  506. 18:24can actually tell you what the event is
  507. 18:25. An event is a very large object. We
  508. 18:27won't go into too much detail about it
  509. 18:28right now. So, look, I clicked here.
  510. 18:30All the elements are displayed. Now I
  511. 18:32click on this button. Look, here comes
  512. 18:35the mouse event because e is a mouse
  513. 18:37event, but it has many values. Is
  514. 18:40trusted true, and within the prototype,
  515. 18:41you get many more values. As we saw in
  516. 18:43the node list, we'll inspect that too
  517. 18:45and read about it completely. And then
  518. 18:48what happens is, you also have this
  519. 18:50span list element because event dot
  520. 18:51target, which target this event came
  521. 18:53from. So, inside that, you've got an
  522. 18:55HTML span element, and you've got these
  523. 18:58attributes. So, right now you have gray
  524. 19:00. Now, if I click on the yellow one,
  525. 19:02look, let's zoom in on the HTML span a
  526. 19:04little bit for you. So look, you've got
  527. 19:06an HTML span here, and here you've got
  528. 19:08attributes, and this time you've got a
  529. 19:10yellow button. Earlier, you had a gray
  530. 19:12button. So, by typing "event.dot.target
  531. 19:14," you know where this event is coming
  532. 19:16from. We'll talk about this in more
  533. 19:18detail. So, now that I know there's an
  534. 19:20event.dot.target, I can extract the ID
  535. 19:22from within it. How do I extract the ID
  536. 19:24? By adding a dot.dot.id, I'll get
  537. 19:26whatever the gray/yellow is. So, what
  538. 19:28do I do now? Now that we've discussed
  539. 19:30this much, everything else is easy. You
  540. 19:32can use an if else statement. You can
  541. 19:33use a switch case, just like I do with
  542. 19:35an if else statement. Okay? So, I've
  543. 19:38simply used an if statement. Inside the
  544. 19:40if statement, I'll check the value of
  545. 19:43the event.dot.target and the ID we're
  546. 19:46getting inside it. So, what do we have
  547. 19:49first? It's gray. So, I'll select gray.
  548. 19:52Now, I'll have to see if I've written "
  549. 19:55GREY" or "A." Ah, yes, sir. I've
  550. 19:58written "GREY" here. Okay? The tea will
  551. 20:02continue to run. See, if the code works
  552. 20:04, the tea will also work. Please ignore
  553. 20:06that. Okay? So what am I going to do
  554. 20:09here? I already have a body. You know
  555. 20:11that. Look, I've given you so much
  556. 20:14practice in the DOM that if you go in
  557. 20:16this far, you can change the color of a
  558. 20:18body. Okay? Body dot, here, take the
  559. 20:23style. Now what? Background color.
  560. 20:26Background color. Okay, sir. Now what
  561. 20:28do you want to do with this background
  562. 20:30color? If you want, you can also
  563. 20:31hardcode a value here. Gray. Or if you
  564. 20:34want to get a little more programming
  565. 20:36practice, what do you actually do?
  566. 20:38Instead of hardcoding a value, write e
  567. 20:41dot target dot ID, because the value
  568. 20:44inside it is gray too. So you can write
  569. 20:47it like this. Okay? So there you have
  570. 20:50it. Okay, sir. So now let's minimize it
  571. 20:53and see, click on gray. The body has
  572. 20:55turned gray. Very easy. You can refresh
  573. 20:58it again. Click this and it's gray. Now
  574. 21:01what can I do in the same way? I can
  575. 21:02change more values. So, okay? It's gray
  576. 21:05. This will turn white. This will turn
  577. 21:07blue. This will turn yellow. Okay? I
  578. 21:08just copied and pasted it, what else
  579. 21:09have I done? So what do I have to do?
  580. 21:11Just come here and write, "Look, this
  581. 21:13is white. This is blue. And this is
  582. 21:17yellow." If you want to add more
  583. 21:19buttons, add more. What's the worry?
  584. 21:21What's the worry? That's all I had to
  585. 21:24do. So, look, this is gray. This is
  586. 21:25white. This is blue. This is yellow.
  587. 21:27That's all I had to do. Now, what's
  588. 21:30even better than this? I can go into
  589. 21:32the index HTML here and tell it, "Hey,
  590. 21:34do one more thing, duplicate it. And
  591. 21:37this time, what's the ID for it? Make
  592. 21:38it purple." Let's make it purple. Here,
  593. 21:42purple. So, you've done this purple.
  594. 21:44But obviously, the class is button,
  595. 21:46with an ID of purple. So, I don't have
  596. 21:48purple in my CSS right now. But okay,
  597. 21:50it doesn't say purple in the CSS, it'll
  598. 21:52only show white; but I know it's purple
  599. 21:54inside. So what will change in the code
  600. 21:55? Nothing will change in the code. What
  601. 21:57do you have to do? Check that its ID is
  602. 21:59purple, so you set its color to the
  603. 22:02same purple as the target color. So, I
  604. 22:05saved it. Now click here. Obviously,
  605. 22:07it's set to purple. Obviously, I didn't
  606. 22:09denotate it as purple in the CSS, but
  607. 22:11you can understand this much; now
  608. 22:12you're advanced. You're starting to
  609. 22:14understand things. Okay? I just did
  610. 22:16this to show you a demo. So, if you
  611. 22:18need this code, you already have it. So
  612. 22:20, it's obvious you'll say, "Sir, give
  613. 22:21me the code," because if I can't do it,
  614. 22:23at least I can see the reference. Yes,
  615. 22:25absolutely. So we'll copy this and go
  616. 22:27to the top of our browser and here's
  617. 22:30the console log. Hitesh, I'll leave it
  618. 22:32there and write all the code below it.
  619. 22:34So what does this do? I wrote this code
  620. 22:36. So all this code is available to you
  621. 22:38here. Okay? Okay? So I'll push it to
  622. 22:40the top to show that we've completed
  623. 22:42Project One. So this is our Project One
  624. 22:47complete. You can't call it complete.
  625. 22:51Let's write the solution code. Oh, I
  626. 22:54don't know what the keyboard is doing.
  627. 22:56Solution code. Okay, sir. Let's commit
  628. 23:00it. Okay, so how do we commit? We
  629. 23:02haven't even staged it before. Yes.
  630. 23:04Should we make a video on the gate? We
  631. 23:06will. We will. We will very quickly. So
  632. 23:07let's commit this and push it so you
  633. 23:10can easily get the code. Okay, sir. Now
  634. 23:15let's go here and refresh the code to
  635. 23:17see if it's loaded or not. So this is
  636. 23:20our Project Seven. Okay, sir. We have
  637. 23:22its Markdown file. There you go, it
  638. 23:24looks great just by clicking. You don't
  639. 23:26have to do anything. You've got a copy
  640. 23:27automatically because it's marked down.
  641. 23:29Just click. See how easy it was to copy
  642. 23:31all the code? Okay? So, you've learned
  643. 23:34quite a bit about how to use events,
  644. 23:36how to use them, and how to manipulate
  645. 23:39documents. Now, let's tell you the best
  646. 23:42part: you said, "Sir, you've done it."
  647. 23:45Now, how do I practice here? Your
  648. 23:47practice is very easy. Go to this URL.
  649. 23:50Now, we're on another URL. We'll go
  650. 23:52back here and copy the URL link from
  651. 23:54here. Copy the link address here and
  652. 23:58open a new tab. Where do we open a tab
  653. 24:01in Safari? I rarely use Safari. So,
  654. 24:04okay. Leave this page. We're back on
  655. 24:07the same page. Open it in Safari, or in
  656. 24:10Chrome, wherever you want. You've got
  657. 24:13the project. Now you go here and say, "
  658. 24:15This is what I want to do, a color, a
  659. 24:18background changer, and then go into
  660. 24:20the code. See, there's no code involved
  661. 24:22. Practice as many times as you want.
  662. 24:24Do it in different ways. Do it with if
  663. 24:26else, do it with switches. Whatever you
  664. 24:28want to do, if you want to use another
  665. 24:30approach, use that approach. So look
  666. 24:32what a great playground we've created
  667. 24:33for you. So, this gets you a like and a
  668. 24:36share. Okay? So you get it. Now let's
  669. 24:40move on to our second project, which is
  670. 24:44much easier than comparison. This one
  671. 24:46requires a small formula. We won't go
  672. 24:49into the formula much. You can look it
  673. 24:50up whenever you want. Simply Google it
  674. 24:55and type in" How to find a BMI index. "
  675. 25:02Here you go. So, I need the BMI index
  676. 25:06formula. So, you'll get the formula:
  677. 25:09weight in kilograms divided by height
  678. 25:11in meters squared. And it's also listed
  679. 25:14here, saying," You can square this by
  680. 25:15multiplying your height by your weight.
  681. 25:17"So, we won't delve too much into the
  682. 25:18formula, as it's a mathematical term.
  683. 25:20You can use it at any time. The basic
  684. 25:22idea is how we'll handle this project.
  685. 25:24So, click back. We're starting the
  686. 25:26project from here. Please enter the
  687. 25:28time stamp. You can do this at least.
  688. 25:30So, we'll add the BMI generator here.
  689. 25:32Look, we need your height in
  690. 25:33centimeters. Enter your weight in
  691. 25:35kilograms. And as soon as you click"
  692. 25:37Calculate, "you'll see a calculation.
  693. 25:40And BMI is a guide to what's
  694. 25:42underweight? So, if your ratio is like
  695. 25:44this," normal "is like this,"
  696. 25:46overweight "is like this, then you get
  697. 25:48the values. So, how will we handle this
  698. 25:50project? First, we'll look at what this
  699. 25:52project does and what its HTML looks
  700. 25:54like. So, here's its HTML structure.
  701. 25:56Now, because I obviously made some
  702. 25:58changes here, I'll have to change the
  703. 26:00workspace settings again so you can see
  704. 26:02the code. Let me do one thing: I'll
  705. 26:05save the changes right in front of you,
  706. 26:07so you can see it. So, I'll permanently
  707. 26:10change the workspace settings to make
  708. 26:12it a little easier. So, let's change
  709. 26:15the font size back here. So, let's make
  710. 26:20it 20. You're also so small, oh, what
  711. 26:23happened? 20. Yes, sir. It's fine now.
  712. 26:26So, I'll save it here. Now, when I save
  713. 26:28something here, what actually happens?
  714. 26:30You get all the saved files there by
  715. 26:33default. So, I don't have to do
  716. 26:34anything. I just reload it once, and
  717. 26:37now I'll have all those settings on by
  718. 26:41default. Yes, once I propagate it here,
  719. 26:44everything automatically comes in.
  720. 26:45Sometimes it takes a little time, a
  721. 26:46couple of minutes, but that's fine.
  722. 26:49Let's refresh it one more time. Here we
  723. 26:53go. Yes, sir. Right now we're seeing a
  724. 26:56bit of code. Okay? That's why I'm not
  725. 26:58doing it in my own, because if I save
  726. 26:59anything there, everyone will see it. I
  727. 27:01want us to play in the Playground. Okay
  728. 27:03? Okay? So here we are in the HTML. So,
  729. 27:05inside the HTML, we have a basic
  730. 27:07navigation bar at the top. Here we have
  731. 27:10a full div, which is a container.
  732. 27:12Lastly, our script is loading the
  733. 27:14JavaScript key code. This is our BMI
  734. 27:16calculator. Okay, sir? Here's the BMI
  735. 27:18calculator. Now here we have a form.
  736. 27:21Now, look, when events occur on a form,
  737. 27:23many other concepts arise. We won't
  738. 27:25discuss that right now. There's also
  739. 27:26the concept of event bubbling. There's
  740. 27:27a lot of other things. We won't discuss
  741. 27:29that right now. We'll discuss it in an
  742. 27:30extra dedicated video. So, don't go
  743. 27:32into that right now. So, look, here you
  744. 27:34have a label. Next, you have an input
  745. 27:36and a height from the input. Now, the
  746. 27:38first problem we'll solve is how to
  747. 27:41extract values from the input. Right?
  748. 27:43That's done through events. Then,
  749. 27:46there's another label with an ID called
  750. 27:47" weight, "so we need to extract the
  751. 27:49value from there. Okay, so once we have
  752. 27:52the value, I can simply calculate it.
  753. 27:54Whether I multiply it or divide it,
  754. 27:55whatever I'm doing isn't a big problem.
  755. 27:57Second, here's our result. Now, what's
  756. 28:00the result? If you type" Hitesh, "you
  757. 28:03get" Hitesh. "This is the result. By
  758. 28:06default, there's nothing inside it. But
  759. 28:08we'll replace it here. So, we've
  760. 28:10studied how we can take inner html and
  761. 28:12inner text, and inject them into the
  762. 28:14DOM. Okay? It's very easy. We'll do
  763. 28:16that too. And whether this guide is
  764. 28:18just for you or for the user who uses
  765. 28:20it isn't something we care about. So,
  766. 28:22you see, it looked quite complex. But
  767. 28:24once you analyzed it a little, you saw
  768. 28:26that there wasn't anything quite that
  769. 28:27big in it. So, okay, let's move on. Now
  770. 28:29, when I saved it here, the project
  771. 28:31changed. But actually, there's no
  772. 28:32change because I'm not signed in yet,
  773. 28:34so there's no problem with it. So,
  774. 28:36let's move on. So, what do we do first?
  775. 28:39We need to select this form. So, why do
  776. 28:42we need to select the form? Because,
  777. 28:44look, we need to select the entire form
  778. 28:46because you have a submit button within
  779. 28:48that form. As soon as you go here, the
  780. 28:50calculate BMI button is actually the
  781. 28:52submit button. When submitting the form
  782. 28:55, we'll talk about events here. We'll
  783. 28:57use a submit type event. There's no
  784. 28:59click event here because it's a form.
  785. 29:01That's why I was telling you to be
  786. 29:02patient. For example, if we study
  787. 29:04events, it will be more convenient for
  788. 29:05you. But that's okay, we can learn some
  789. 29:07things on the go. Okay? So what should
  790. 29:09we do first? Here we have the document.
  791. 29:12Next, the query field. What's inside
  792. 29:14the query field? Just provide it
  793. 29:16directly. There's no need for a class
  794. 29:17ID. Here you go, form. Hold it in a
  795. 29:19variable. There you go, that's it. Okay
  796. 29:22? So we have the form. Okay, sir. That
  797. 29:24much is clear to us. Here we have the
  798. 29:27complete form. This form is completely
  799. 29:29in our hands. Okay? Now what is a form?
  800. 29:32Whenever a form is submitted, you've
  801. 29:34probably read that a form is submitted
  802. 29:36using either a post type or a get type.
  803. 29:38But whenever a form is submitted, its
  804. 29:40values are sent to the URL or to the
  805. 29:42server. We need to stop that, because
  806. 29:44we're not sending it to the server. So
  807. 29:46stop the default action of the form
  808. 29:48right here. Okay? What do we need to do
  809. 29:51to stop that? First, you get a method
  810. 29:53directly on events. Yes, it will work.
  811. 29:58Look, if there's code, it will work. So
  812. 30:00, look, there's a form, and you have
  813. 30:02the same add event listener on it. Yes,
  814. 30:04it's the same add event listener
  815. 30:05everywhere. So, which event are you
  816. 30:07looking at this time? Not our click,
  817. 30:09not that click event. This time we're
  818. 30:11looking at the submit event. So, where
  819. 30:12can we find a list of these events? I
  820. 30:14just told you we need to be patient.
  821. 30:16We'll have to look at it when we talk
  822. 30:18about events. Okay? Again, you get a
  823. 30:20callback. So, here we go, callback.
  824. 30:22What do you get inside the callback? E
  825. 30:24event, Chai, Superman, whatever you
  826. 30:26want to call it. Okay? So, what's the
  827. 30:28first thing we do? With E, we tell it
  828. 30:30to prevent default. That means,
  829. 30:32whatever your default action is, stop
  830. 30:34it for 1 minute. Don't vomit submit.
  831. 30:37Okay? Now, what do we need? What values
  832. 30:41do we need? It's very easy to see. We
  833. 30:43need this height, and we need this
  834. 30:45weight. Okay? Now, what we do is select
  835. 30:49those values every time an event occurs
  836. 30:51in the form. What do some people do?
  837. 30:53They select them right here. Well,
  838. 30:54there's a big difference. First, I'll
  839. 30:55explain how to select them here. Then
  840. 30:57we'll discuss the difference. So, what
  841. 31:00will we do? Simply put, add a query
  842. 31:02variable to this document. What do we
  843. 31:05need after adding a query variable? We
  844. 31:07have the ID. So, we'll give you the ID.
  845. 31:09Here you go. We'll give you the ID
  846. 31:11first. What height? Give the weight.
  847. 31:12Give the height. Here we go. We've
  848. 31:14given you the height. Okay, what do you
  849. 31:15do after giving the height? Just type
  850. 31:17in the dot value and you'll get the
  851. 31:18value. It's a very easy process. So,
  852. 31:20this is how you get the input values.
  853. 31:23Okay? But how do you get the values? In
  854. 31:25a string. And remember? Back when you
  855. 31:27thought the series was boring. Yes,
  856. 31:29back then we taught you how to pass a
  857. 31:32string to an int? You can pass it to a
  858. 31:35float, by the way. So, here we are, we
  859. 31:37wrapped it. And told it what to do? Ah,
  860. 31:41simply parse it to an int. So now
  861. 31:43whatever value you got in the string
  862. 31:45has been parsed to an integer. Okay? We
  863. 31:47haven't checked here yet whether it can
  864. 31:49be parsed or not. Did someone write" a
  865. 31:51"or" what "? Let's not worry about that
  866. 31:52right now. We'll worry about it when we
  867. 31:54make a more complex project. Let's hold
  868. 31:56on to this one. Here, let's call it"
  869. 31:58height. "Here, okay? Let's move it a
  870. 32:02little to the side so you can see it
  871. 32:03easily, because the tech isn't what
  872. 32:05we're concerned with. As for the UI,
  873. 32:06the UI is whatever. Let's take another
  874. 32:08copy of it. Let's call it" here. "What
  875. 32:12did I write here? What all did it open?
  876. 32:16Okay. Here, I wrote" weight. "And
  877. 32:19obviously, its ID is also written here,
  878. 32:22weight. So, what's the difference
  879. 32:25between writing this height here versus
  880. 32:27writing this height outside the form?
  881. 32:30Look, what's the actual difference?
  882. 32:31You're trying to get those values right
  883. 32:34when you click. You're trying to get
  884. 32:36those values during that event. Because
  885. 32:38what will happen? What will happen if
  886. 32:39you write those values outside here?
  887. 32:41Your script runs as soon as the page
  888. 32:43loads, and that empty value will be
  889. 32:45stored inside this height. So, do you
  890. 32:48want an empty value or some value
  891. 32:50inside it? The use case depends on you.
  892. 32:51Our use case right now is that we want
  893. 32:54to extract whatever values are inside
  894. 32:56that values after submitting. We don't
  895. 32:58want empty values. So, if you write it
  896. 33:00here, it will be wrong. So, what will
  897. 33:03happen? This use case will give you
  898. 33:09empty values. I've seen a lot of people
  899. 33:12, teaching for various companies, in
  900. 33:14various courses. People there are
  901. 33:16constantly worried about how their
  902. 33:18values are coming up empty, because the
  903. 33:21code after this is so simple. There's
  904. 33:23nothing after that, actually. Okay? Let
  905. 33:25me tell you a little about our code,
  906. 33:27which calculates the height and weight
  907. 33:29we just took. It could be completely
  908. 33:30broken. So, let's do a few checks. I
  909. 33:33won't discuss many checks right now,
  910. 33:35because we're not at that stage of such
  911. 33:37complex code, but let's talk about a
  912. 33:39few positions. So, what do we do?
  913. 33:43Actually, if you look closely, we have
  914. 33:45a result. Right? We haven't taken the
  915. 33:47result yet. We'll take that too. We'll
  916. 33:49actually take it right here. If you
  917. 33:51look carefully, we've talked about this
  918. 33:53a little bit. This is the results ID.
  919. 33:55Let's take this as well so we can get
  920. 33:57the results. We also get the results
  921. 33:59here. So let's call it results or
  922. 34:02results. They are actually results. Yes
  923. 34:04, they are results. So we'll call this
  924. 34:06results as well. And we get them
  925. 34:07through the query vector. There's no
  926. 34:09need for dot value. So here you go, dot
  927. 34:11results, and there's no need for
  928. 34:14percent because it's just one element.
  929. 34:17So here you go. So here you go. Okay?
  930. 34:21Now what are we going to do? We'll do a
  931. 34:22little check. If all those checks are
  932. 34:24correct, what will we do? We'll add
  933. 34:25values inside results. So, to add
  934. 34:27values, we know innerHTML is very easy.
  935. 34:30If you want, we've already discussed
  936. 34:31innerText. We won't do it again. So
  937. 34:33what are we going to do here? Please
  938. 34:37give a valid height because we're
  939. 34:42checking for height. As it is, we'll
  940. 34:44copy this and then. So, what other
  941. 34:46checks can we apply? So, look, the
  942. 34:47height has been parsed into an int. So,
  943. 34:50what's the first thing? It shouldn't be
  944. 34:52empty. Okay? And the second condition,
  945. 34:55since I'm talking about it, add another
  946. 34:58value. Here, what else would you like
  947. 35:01to check? So, what other values are
  948. 35:04there? What else do you want? If it's
  949. 35:06less than zero, I don't want it. Okay?
  950. 35:09And if it's not a number, that is, not
  951. 35:11a number at all, then what's the point?
  952. 35:12So, what's the point here? There's an
  953. 35:14old technique and a new technique. Many
  954. 35:15people check if height is equal to or
  955. 35:19not equal to, like checking if height
  956. 35:22is not equal to N. This is actually an
  957. 35:25old technique. Don't use it. I'll tell
  958. 35:28you a better technique that's still in
  959. 35:29use today. And actually, the updated
  960. 35:31JavaScript technique is recommended in
  961. 35:33the documentation. What they say is
  962. 35:35that you use this NN method and you
  963. 35:38pass in the height. So if it's 'true',
  964. 35:42then the 'true' height. If it's 'true',
  965. 35:44meaning it's convertible to a number,
  966. 35:45not a number, it's convertible to a
  967. 35:47number, so you'll get the value 'true',
  968. 35:48so there's no problem. And if it's '
  969. 35:51false', then we don't want to proceed,
  970. 35:52okay? So you'll get it, basically, okay
  971. 35:54. So now we'll save it, because we've
  972. 35:56already done all this work, so we'll
  973. 35:57check it first. So look, now we've
  974. 35:58passed in 'calculate', so it's saying,"
  975. 36:00Please give a valid height. "Okay, it's
  976. 36:02scrolling now, that's fine, no problem.
  977. 36:04And what can we see here next? If I
  978. 36:06give height an 'a', which can't be
  979. 36:09converted, and give it 'calculate', it
  980. 36:11will say" please give a valid one. "And
  981. 36:13if I give it a 'three' here, and then '
  982. 36:16calculate', it won't say anything. We
  983. 36:18haven't reset it yet. Okay? That's it.
  984. 36:21But if I want, I can also give a height
  985. 36:22value here. So if you want, we can
  986. 36:24convert it back to text so you can see
  987. 36:27that the value is actually changing. So
  988. 36:29here we are, I've given it the dollar
  989. 36:31value, and whatever the height value is
  990. 36:33, we'll also give it the height value
  991. 36:35here. Okay? When I save it, suppose it
  992. 36:37gives a. When I calculate, it says,"
  993. 36:39please give a valid height. "Not a
  994. 36:41number, that's great. And if I give it
  995. 36:44three here, then calculate, it says"
  996. 36:46please give a valid height. "A,
  997. 36:47actually, we're changing it because if
  998. 36:50this condition is met, then it will
  999. 36:52only run, and this value will only be
  1000. 36:54set when it runs. Okay? You understand
  1001. 36:56the code logic. Otherwise, what should
  1002. 36:57we do? Set it to height. Okay, sir? So
  1003. 37:00just to see. So let's save it. So here
  1004. 37:03we go to four. When we calculate, we
  1005. 37:05see that four is set. But if we
  1006. 37:07calculate 4A, that also gets converted
  1007. 37:09to four. But if you calculate AA, it's
  1008. 37:12not a number. I had you discuss this
  1009. 37:14whole thing in the beginning. I hope
  1010. 37:17you remember. Okay, sir? So, you
  1011. 37:19understand. Now we'll do the exact same
  1012. 37:21thing in weight. I did this just to
  1013. 37:23explain it to you. Let's copy and paste
  1014. 37:26this. Here. Now check weight in the
  1015. 37:28same way. Weight has the same checks.
  1016. 37:31That the weight should not be empty.
  1017. 37:33Even zero. Okay, we need to check the
  1018. 37:34weight here as well. Let's copy this so
  1019. 37:37I don't make any spelling mistakes
  1020. 37:40everywhere. Here we go. Okay? So we
  1021. 37:46have the weight. Okay. So we'll write
  1022. 37:49the weight here as well. Okay, sir. So
  1023. 37:52we've done that much work now. Perfect,
  1024. 37:55now we have both the height and the
  1025. 37:57weight. Okay, sir. Now what do we do if
  1026. 38:00everything is working fine here, that
  1027. 38:01is, if we have the height, what do we
  1028. 38:03do here? We'll actually put an if
  1029. 38:05because the height will be checked, and
  1030. 38:06the weight will also be checked.
  1031. 38:08There's nothing wrong with this code.
  1032. 38:10But okay, for better syntax, we'll put
  1033. 38:13an if and move it to the same line. So,
  1034. 38:16else if the weight has been checked as
  1035. 38:17well. Okay. If all this is checked,
  1036. 38:20then what do we do in the else case
  1037. 38:22here? Okay, if everything is fine, what
  1038. 38:25do we do? Calculate the BOMI. Now, to
  1039. 38:26calculate BMI, we need a full value.
  1040. 38:29Look, I won't bother you too much with
  1041. 38:30the full value here. Because, look, you
  1042. 38:32can write it however you want. I'll
  1043. 38:34give it to you directly. Here, I've
  1044. 38:36written it down in my notes. So, this
  1045. 38:38is the full value we have. Okay? What
  1046. 38:40the full value says is, as we just saw
  1047. 38:42in How to Find a BMI Index: weight in
  1048. 38:45kilograms divided by height in meters
  1049. 38:47squared. So, it's the exact same value.
  1050. 38:50We have the weight, and then we
  1051. 38:52multiply the height by it because we
  1052. 38:54need it in that exact value. And height
  1053. 38:57squared is height*height. So, okay,
  1054. 38:59we've taken that and used 'to fixed to
  1055. 39:01() because after multiplying and
  1056. 39:02dividing, the number often ends up
  1057. 39:04being very long. We don't need that
  1058. 39:06much after the decimal point, so we've
  1059. 39:07added' to fixed 'here to show up to two
  1060. 39:09decimal values; I don't need anything
  1061. 39:10beyond that. So, that's our formula.
  1062. 39:13Now, look, you can create your
  1063. 39:14temperature in the same way, and you
  1064. 39:15can add the full value. That's the
  1065. 39:17mathematical part, not really a coding
  1066. 39:19part. So, let's take this and call it a
  1067. 39:22() const, and call it bmi (). So, there
  1068. 39:25we have bmi. This is bmi calculated,
  1069. 39:27that's it. Now, what do we do next? We
  1070. 39:29need to display this bmi in the results
  1071. 39:31. So, show the results. Okay? Now, how
  1072. 39:38do we show the results? It's very
  1073. 39:40simple. Here we have our results. Okay?
  1074. 39:43And what do we do inside that? Add
  1075. 39:44inner h tm l. Inner HTML. So what do we
  1076. 39:47do with inner HTML this time? We take
  1077. 39:49the back text and add it to the span.
  1078. 39:50Because it will be useful later. Yes,
  1079. 39:51there's a project coming up where we'll
  1080. 39:53write values like this. It's better to
  1081. 39:55get some practice in now. Okay? Here
  1082. 39:59you go. We wrote this in a span and
  1083. 40:01injected the values inside the span. So
  1084. 40:04here we go, take this with the dollar
  1085. 40:06sign, and say, here you go, your BAMI
  1086. 40:08is injected. Okay, sir. That's all we
  1087. 40:10had to do. So we saved it and said,
  1088. 40:13okay, let's say someone's height is 180
  1089. 40:16cm, and 65 is the fictitious value.
  1090. 40:19Calculate BAMI, and it calculated it.
  1091. 40:22If you enter' a 'instead of 65,
  1092. 40:23calculate it, then it said," Please
  1093. 40:25give a valid height. "Okay, didn't I
  1094. 40:28change the message? Look, I didn't
  1095. 40:30change the message. So it gives the
  1096. 40:32weight again, okay? So, 160 cm, and
  1097. 40:35here it gives' q '. So it said," Hey,
  1098. 40:38give a valid weight. "Okay, okay! Sorry
  1099. 40:40, I made a mistake. So okay, let's give
  1100. 40:42someone a valid weight of 88, so we've
  1101. 40:44calculated 34. Now what can you do?
  1102. 40:47This is your task, your assignment,
  1103. 40:49based on the range I've given you,
  1104. 40:51right? So, based on this, you have to
  1105. 40:54print another message here, after a
  1106. 40:56line break inside this inner HTML file,
  1107. 40:58stating whether your value is actually
  1108. 41:00underweight, in the normal range, or
  1109. 41:02overweight. Okay? So, you've done this
  1110. 41:05little assignment. Now you'll need this
  1111. 41:07code as well. Yes, you'll need the
  1112. 41:09entire code. Okay? So let's come back
  1113. 41:12here and go to our Chrome and here this
  1114. 41:16Project 2. Okay, so this Project 2 here
  1115. 41:20, let's add another one. Let's call it
  1116. 41:26Project 2 Solution. I'm writing this
  1117. 41:30triple back text j script so that it's
  1118. 41:32easy for you to copy and paste a little
  1119. 41:34bit easily when you look at the get up
  1120. 41:37there. So here I am, I've pasted it.
  1121. 41:39Look how well it looks. Project
  1122. 41:41Solution Solution One Project Two
  1123. 41:43Solution. Okay? The assignment is also
  1124. 41:46nicely included here. So please take
  1125. 41:48care of that. Let's save it and push
  1126. 41:50the code right in front of you. Here,
  1127. 41:54Project Two Solution, let's commit it
  1128. 42:01and push it too. Okay? It's a bit hot
  1129. 42:06today. So the AC keeps going off and on
  1130. 42:09. So, that's all the work we have.
  1131. 42:11Let's go back to our Safari. So, that's
  1132. 42:14our project. Let's close it. Let's
  1133. 42:16refresh. You know, all the values will
  1134. 42:18disappear. Now let's go back to Home.
  1135. 42:21Okay? We're back to Home. So our BMI
  1136. 42:23calculator is done. Now let's do a
  1137. 42:25simple project. Very simple. You might
  1138. 42:27not have done a project easier than
  1139. 42:28this. But actually, this timing game
  1140. 42:30within JavaScript is quite complex.
  1141. 42:32It's very interesting. We'll talk about
  1142. 42:33this sometime, discuss it. Now let's
  1143. 42:35come to our digital clock. So this is
  1144. 42:37our digital clock. What do we need to
  1145. 42:39do? You need to display the local time
  1146. 42:40here. Okay, sir? It's very easy. So
  1147. 42:42let's dig into our code. Here's three,
  1148. 42:45this digital clock, and this code. Okay
  1149. 42:49, first, the index. So let's read it
  1150. 42:51here. Now, what's inside the index?
  1151. 42:54This is the CSS I wrote. Okay? We have
  1152. 42:56a center div, I've placed a flex box,
  1153. 42:59etc. here. And this is our banner for
  1154. 43:01the local time, and we've given it an
  1155. 43:03ID for the clock, which is displayed in
  1156. 43:04orange. So that's it. Display the time.
  1157. 43:08Okay, sir. So, here's the code. Now,
  1158. 43:10how do we display the time? First, we
  1159. 43:12need something to display the time.
  1160. 43:14Where do I display it? So, what do we
  1161. 43:15do? Take the clock as a reference and
  1162. 43:17display it here. Okay, now how do I get
  1163. 43:19the clock? Let's take it as a reference
  1164. 43:21, document.a.query. Okay? This time
  1165. 43:24we're using something new: Get Element
  1166. 43:25by ID. Okay? Just for fun. Use whatever
  1167. 43:27you want. There's no problem. Okay?
  1168. 43:30We've got it. Get Element by ID. And
  1169. 43:32what about the ID? So, we'll put the
  1170. 43:34clock here. Okay? If anyone's having
  1171. 43:36trouble, what can they do? That
  1172. 43:38document.query.sector. I'm going to
  1173. 43:41explain it to you in different ways
  1174. 43:43because the code you read will be read
  1175. 43:45differently. So, here's the query. What
  1176. 43:48do you do in the query.sector? Nothing,
  1177. 43:50just give the ID. Okay? I've given you
  1178. 43:55the clock. Now, take whatever you want.
  1179. 43:57We can even store it in a variable. So,
  1180. 43:59let's call it clock. Take this. If you
  1181. 44:02don't want one, take this one. Don't
  1182. 44:05take two. Just comment out one. I'll
  1183. 44:08use the first one for you. Right now,
  1184. 44:09both are going to return the same value
  1185. 44:11. We already know that much. Now, it's
  1186. 44:12not a big deal. So, what we need to do
  1187. 44:14now is display the clock. Well, we
  1188. 44:16don't need to display a clock like this
  1189. 44:17. It's a digital clock. So, it should
  1190. 44:19change every second. Look, if you want
  1191. 44:21a clock, you can get it very easily.
  1192. 44:23There's nothing to do with it. What do
  1193. 44:24you need to get a late date or a date?
  1194. 44:26Simply get a date. New Date. Date is a
  1195. 44:29direct object. Okay? We have the date.
  1196. 44:33So, if you want to display this date,
  1197. 44:34what can you do? So, you can go to
  1198. 44:38console. console.log and say," This
  1199. 44:43date has a method called' to local
  1200. 44:47string '. There's also' date string ';
  1201. 44:50we'll use' time string 'and this method
  1202. 44:52. That's it, you're done. So, the
  1203. 44:54problem is that it hasn't appeared here
  1204. 44:56yet. When I open the console, I have
  1205. 44:58the time. Every time I save it, I'll
  1206. 45:02get the time. Okay, every time the page
  1207. 45:05refreshes. "I'll keep getting the
  1208. 45:07updated time every time. But what do I
  1209. 45:09want? This date should run every time.
  1210. 45:11It should run repeatedly, and it should
  1211. 45:13keep updating here. Now, if I knew of a
  1212. 45:15method in JavaScript that would run
  1213. 45:18every moment, or I could control
  1214. 45:20whether I want it to run after 1 second
  1215. 45:22or 2 seconds. If I want it to run every
  1216. 45:24time, how would I do that? Some people
  1217. 45:26will come here very intelligent and say
  1218. 45:28," Set up a cron job. "Hey, what are
  1219. 45:30you talking about? You've become so
  1220. 45:32advanced that you've reached the top of
  1221. 45:34the server that you'll set up a cron
  1222. 45:35job. This is where you fail the
  1223. 45:37interview. Because you're asking for
  1224. 45:39advice, it's a small matter, like a
  1225. 45:40needle. You're drawing your sword. How
  1226. 45:43will that work? So, what do you need to
  1227. 45:45do here? You need to know a simple
  1228. 45:47method that controls JavaScript events.
  1229. 45:49That's your setInterval method. It lets
  1230. 45:52you give me any method and specify the
  1231. 45:54interval after which I'll run it
  1232. 45:56continuously. It'll run for as long as
  1233. 46:00your program runs or as long as the
  1234. 46:02script is open. We'll discuss this
  1235. 46:04further because it causes many
  1236. 46:05JavaScript interviews to fail. Yes,
  1237. 46:07we'll discuss this too, but now you
  1238. 46:09know. So, there are two parameters:
  1239. 46:11this is the function, and this is the
  1240. 46:13function's body, and the second
  1241. 46:14parameter, separated by a comma, is the
  1242. 46:16time. It's in milliseconds. Give it
  1243. 46:181000. For 1 second, give it 2000.
  1244. 46:20Always write it this way. If you don't
  1245. 46:23write it this way, you're sure to make
  1246. 46:25mistakes in syntax, and you won't get
  1247. 46:27code highlighting, which is a feature
  1248. 46:29of many interviews. Yes, there are many
  1249. 46:31interviews where you don't get code
  1250. 46:33highlighting or color highlighting. So,
  1251. 46:36remember to write it this way. What do
  1252. 46:38you have to do? Write this set interval
  1253. 46:39. After that, there are two parameters.
  1254. 46:41First, write the first parameter. This
  1255. 46:42is how we wrote the function. We wrote
  1256. 46:44the body of the function. After that,
  1257. 46:46we put a comma and put 1000 here. If we
  1258. 46:48want to give 2000, then for 2 seconds,
  1259. 46:50as the interviewer is asking you,
  1260. 46:52whatever your task is. Okay, now what
  1261. 46:53do we have to do? We don't have to do
  1262. 46:55anything. This is what we had to do. So
  1263. 46:57, let's cut it and give it to him. Now,
  1264. 47:00these values will come to us every
  1265. 47:03second. So, let's save it and see. So,
  1266. 47:05let's look in the console. Now, see,
  1267. 47:06these values are coming to me every
  1268. 47:08second. 26 27 28 So, that's all we've
  1269. 47:11got. But I never actually had to run it
  1270. 47:13in the console. So let's stop it for 1
  1271. 47:16second. So, I never had to run it in
  1272. 47:18the console. So, let's comment it out.
  1273. 47:20Where did I have to run it? I had to
  1274. 47:22update this document. Its node had to
  1275. 47:24be updated every second. Okay? Let's do
  1276. 47:27that. What's the big deal? So here's
  1277. 47:28the clock. What do you do with it?
  1278. 47:29Inner HTML, inner text, whatever you
  1279. 47:31want, I'll take the inner HTML. What do
  1280. 47:33you do with it? Here's what I wrote
  1281. 47:35above, date.com. There are a lot of
  1282. 47:37methods inside it. So I'll use to
  1283. 47:39localize a timestring. And here we go,
  1284. 47:42that's all I needed to do. So now we
  1285. 47:45have a date that's updating every
  1286. 47:47second. Why is it updating? Because
  1287. 47:49this method is running every second.
  1288. 47:51Okay? So that was a small project, but
  1289. 47:53it was quite interesting. Now let's
  1290. 47:56move on to our bigger project. So let's
  1291. 47:58have some tea first, and then we'll
  1292. 48:00move on to the bigger project. Yes, sir
  1293. 48:03. After a sip of tea, we're here. I
  1294. 48:06haven't given you this code yet. Don't
  1295. 48:07worry. I haven't forgotten. I'll give
  1296. 48:09it to you. Don't worry. So let's copy
  1297. 48:11it and run it on our browser. And here
  1298. 48:14we have another one. Okay, sir? I'll
  1299. 48:17give you another one. This is our
  1300. 48:21Project 3 solution code. Here's the
  1301. 48:25back-tech, and the same JavaScript. Yes
  1302. 48:27, by the way, if you ever need to use
  1303. 48:29it for your own use, instead of
  1304. 48:30JavaScript, if you want to write Python
  1305. 48:32code, you can also write Python code.
  1306. 48:34That code is highlighted here. You just
  1307. 48:35have to enter the language. For example
  1308. 48:37, suppose print. Yes, I write a lot of
  1309. 48:39code in Python. I have to write a lot
  1310. 48:41for college right now. So, Hitesh, take
  1311. 48:43this. Look, Python code is also
  1312. 48:44available, and when you look at the
  1313. 48:46get-up, that code can be copied and
  1314. 48:47pasted. Java and Python are available
  1315. 48:48for everyone. Right now, we're focusing
  1316. 48:49on JavaScript. Sometimes we just feel
  1317. 48:51like giving you a little extra
  1318. 48:52knowledge, so we provide it there. Here
  1319. 48:55you go. Now you have the solution code
  1320. 48:57for Project 3. It was pretty easy, but
  1321. 48:58there was no need to provide it. So,
  1322. 49:00okay? But let's provide it. So, write
  1323. 49:04the Project Solution 3 solution
  1324. 49:08properly. Solution 3 code and then
  1325. 49:12we'll do it. The stage is ready. Let's
  1326. 49:15commit and push it. Here, let's push it
  1327. 49:19. Check it once so I know whether
  1328. 49:22you're getting the code or not. So,
  1329. 49:24here you go, and here you have Solution
  1330. 49:28Three. Okay, sir. That's all done. Now
  1331. 49:31let's move on to our larger project.
  1332. 49:33This project will be a little larger.
  1333. 49:34It will be a little time-consuming. But
  1334. 49:38it's not a complex project. Look, after
  1335. 49:40writing so much code, you must have
  1336. 49:41understood. We add logic one by one.
  1337. 49:44It's not so much that we have a problem
  1338. 49:46. There's a little too much fan. Let's
  1339. 49:49reduce it. Wait a second. Yes, sir. So,
  1340. 49:53in this Project Four, we have a lot of
  1341. 49:56code, but it's not complex. Not complex
  1342. 49:59. We'll just add a very small if and
  1343. 50:01else, and it's done. Yes, we'll have to
  1344. 50:03select a lot of values within the
  1345. 50:04documents. But look, select one value,
  1346. 50:07select two values, or select 20 values.
  1347. 50:09The same method needs to be applied
  1348. 50:10within the document. The same query
  1349. 50:11field. So, it's not a complicated task.
  1350. 50:14It's lengthy, I admit. It will take
  1351. 50:15time. So, okay. What is this? Now,
  1352. 50:17guess the number. It's a very simple
  1353. 50:18game. You might have played it too. So,
  1354. 50:19this is guess the number. What it
  1355. 50:21involves is that you try and guess the
  1356. 50:23number between one and 100. Okay? You
  1357. 50:25have 10 attempts to show the numbers.
  1358. 50:27Okay? And guess the correct number. So,
  1359. 50:29you have to guess the number. Here, you
  1360. 50:31have to enter a number. As soon as you
  1361. 50:32submit, that number will be evaluated.
  1362. 50:35And you have to check whether the
  1363. 50:37number is actually correct or not. So,
  1364. 50:39you'll also have to generate a random
  1365. 50:40number. Okay. And what are we doing
  1366. 50:42with the previous guesses? We're
  1367. 50:44creating an array where we'll store all
  1368. 50:46the user's previous guesses and display
  1369. 50:48them to the user. We'll also need to
  1370. 50:54reduce the remaining guesses. With each
  1371. 50:55click, we'll reduce the number of
  1372. 50:57guesses until you have nine attempts
  1373. 50:59left, five attempts left. So, this is
  1374. 51:01how it works. Okay? So, there's a lot
  1375. 51:03involved, but it's not complicated. I'm
  1376. 51:05saying it again, it's not complicated.
  1377. 51:06Let's study it one by one, because it's
  1378. 51:08a great project. You'll have a lot of
  1379. 51:10fun. So, there's a lot of code. Don't
  1380. 51:12be intimidated by the code. So, look,
  1381. 51:14here we have a form. Okay? And here we
  1382. 51:17have a result. Okay? There's no problem
  1383. 51:19at all. Now, within the form, I know I
  1384. 51:22have a guess field, which says" Guess a
  1385. 51:24number. "Okay? After that, there's an
  1386. 51:26input, which is what? There's a" guess
  1387. 51:28"field, and there's an input there,
  1388. 51:30because I can extract values from there
  1389. 51:31. Okay, I'll extract that too. And then
  1390. 51:33what do I have? Input type" submit. "
  1391. 51:36Now, this input type" submit "is
  1392. 51:38actually a button. Yes, you don't
  1393. 51:41always have to write" submit "for the
  1394. 51:43button in the form. You can also write"
  1395. 51:45submit "for the input. Okay? So, this
  1396. 51:47button looks like this. Now, scenarios
  1397. 51:49like this arise, so here's the scenario
  1398. 51:51. And this div below, we have" previous
  1399. 51:55guesses. "Okay? So, we can easily get
  1400. 51:57those as well, called" guesses. "And we
  1401. 51:59can easily get the last result as well,
  1402. 52:02from within 10. Okay? So, it's not that
  1403. 52:04complicated. So, we can get the values
  1404. 52:06here. Okay? Okay? Now, since we have an
  1405. 52:09ID here, where did I actually go?
  1406. 52:12Here's" submit. "So, you know, we've
  1407. 52:14written this down. So, what exactly is
  1408. 52:16this? This is our major click event.
  1409. 52:18Here, we'll have to listen to the event
  1410. 52:20. Okay? I'll show you some more. You'll
  1411. 52:23get the idea. Okay? So, first of all,
  1412. 52:26our challenge is to generate a random
  1413. 52:28number between 1 and 100. So, how is a
  1414. 52:30random number generated? To generate a
  1415. 52:33random number, we use the Math library
  1416. 52:35and use math.random. Okay, sir. Now,
  1417. 52:37what do we do with math.random? We lock
  1418. 52:40the console so you can keep track of
  1419. 52:42what we're actually doing. What actions
  1420. 52:44are happening here. So, here we go.
  1421. 52:47Let's open the console. Here we go. Now
  1422. 52:50, look, every time I save this, every
  1423. 52:52time I refresh the page, I get a new
  1424. 52:55number. But if you look carefully, what
  1425. 52:57is this number? 0.5484. Okay? So now,
  1426. 53:02since all the values are coming after
  1427. 53:04the decimal, if I want from one to 100,
  1428. 53:07suppose I want up to 10, what do I do
  1429. 53:09to jump from the decimal to here?
  1430. 53:11Nothing, just multiply by 10. Hey,
  1431. 53:13basic mathematics, multiply by 10, and
  1432. 53:15one number jumps over here. Okay? Now,
  1433. 53:18every time you refresh this, one number
  1434. 53:19will jump over here. Okay? Now, if you
  1435. 53:23jumped one number over here, it's like
  1436. 53:24this. Now, if you wanted 100, jump two
  1437. 53:26numbers over here. Because you only
  1438. 53:28need up to 99. Okay? Now, there's one
  1439. 53:30more special thing about this. It will
  1440. 53:32give you all the numbers, but sometimes
  1441. 53:34it might also give you zero, because it
  1442. 53:36will give you 0 to 99. Now, I don't
  1443. 53:37need zero. So what I do is I simply
  1444. 53:39come here and tell it to add 1. So here
  1445. 53:42we go, I added 1. Now it's guaranteed
  1446. 53:44that your number can be 100, but it
  1447. 53:46won't be zero. Okay? So you can refresh
  1448. 53:49as much as you want. Now, see, getting
  1449. 53:51the exact zero isn't possible right now
  1450. 53:52in this randomness. But okay. Not only
  1451. 53:55that, I want this decimal that's coming
  1452. 53:57out, I don't want a decimal. I want an
  1453. 53:59integer. So, here we go, wrap it here,
  1454. 54:02and do the same thing we just did in
  1455. 54:05the last video. And simply tell it to
  1456. 54:08parse to an int. So, when we parse to
  1457. 54:10an int, obviously, you know what value
  1458. 54:12we got? So, this is 91, so we took it
  1459. 54:15from one to 100. Okay? So, more values
  1460. 54:19will come out as well. So, one problem
  1461. 54:21has been solved: how to generate a
  1462. 54:23random number. So, why not write this
  1463. 54:24random number to the console? Let's
  1464. 54:26hold it in a value. So, let's call it
  1465. 54:31simply a cost random number. Here you
  1466. 54:35go. Okay? The random number is there.
  1467. 54:38One problem has been solved. But what's
  1468. 54:40the next problem? We need to take a lot
  1469. 54:42of values in the document. So, the
  1470. 54:44document.query field. In the query
  1471. 54:47field, we just read what we have.
  1472. 54:50Actually, let's open this one too.
  1473. 54:52First, we take this one, which is
  1474. 54:54called submit, because many events will
  1475. 54:57be triggered on it. So, here we go. Now
  1476. 55:00, what do we do with it? Let's call it
  1477. 55:02submit button or submit. We can give it
  1478. 55:06good variable names here. If we don't
  1479. 55:07give it in the HTML, that's fine. Okay?
  1480. 55:09What else do we need to take? We need
  1481. 55:10to take user input as well. So, where
  1482. 55:12will we take user input from? We'll
  1483. 55:14take it from the guess field. Obviously
  1484. 55:15, we need its value. So let's copy and
  1485. 55:19duplicate it. We need the query sector,
  1486. 55:22this guess field. And what is this?
  1487. 55:25User input. User input. Now, obviously,
  1488. 55:30what we need here is that this won't
  1489. 55:33suffice. I need to actually get its
  1490. 55:35value. So, you can get it by dot value
  1491. 55:37here, or you can also get it by letter
  1492. 55:39on. Whatever you like. Ah, for now,
  1493. 55:42I'll keep it here because I'm writing
  1494. 55:43all the sectors. Actually, I'm not
  1495. 55:45passing the exact value because
  1496. 55:47wherever I need the value, I'll write
  1497. 55:49it there by dot value. Now, it's up to
  1498. 55:51you which approach you want to use.
  1499. 55:53I'll use this approach for now. Then
  1500. 55:56we'll see what approach we use next. So
  1501. 56:00, let's move on to more values. Okay?
  1502. 56:03If this seems a little problematic to
  1503. 56:04you, we've just tried the dot value in
  1504. 56:06our project. So, you won't be too
  1505. 56:07bothered. Okay? So let's take more
  1506. 56:09values. Okay? Here we are, we have user
  1507. 56:12input. Now, after the user input, let's
  1508. 56:15move on. Here we take the guess slot.
  1509. 56:20So, we'll take the user's guesses, the
  1510. 56:21previous guesses here. So let's call it
  1511. 56:23that too. So, this one we have with a
  1512. 56:26dot is a class. So, these guesses are
  1513. 56:30called guess slots. Because we'll keep
  1514. 56:34filling these slots. We'll have arrays.
  1515. 56:36So, what else do we need? We also need
  1516. 56:38to show the user's last result, what
  1517. 56:40did you provide here, so we'll actually
  1518. 56:42take that as well. The last result
  1519. 56:46value will come to us from last result.
  1520. 56:49This is also a class. So, okay. Let's
  1521. 56:50take this as well. It's not a problem
  1522. 56:52at all. Let's tell it to take this last
  1523. 56:54result from here. And let's take the
  1524. 56:56same name. Its remaining last slot also
  1525. 56:59means how much remaining is left. The
  1526. 57:03last result. Yes, sir. It's the same.
  1527. 57:06Let's save it. Okay. So, is there a
  1528. 57:09problem here? I think it's because it's
  1529. 57:11not loading. So I think we did
  1530. 57:13something. Let's save the remaining.
  1531. 57:16Let's refresh it once. Yes, sir. There
  1532. 57:18is a problem. Give me a second. Let me
  1533. 57:20just select this and see what's causing
  1534. 57:22the problem. Let's debug it. Yes, sir.
  1535. 57:28So after checking, I had to refresh it.
  1536. 57:31Keep in mind when refreshing, if you
  1537. 57:33haven't saved or locked all the code,
  1538. 57:35it will all be lost. Similarly, this is
  1539. 57:37the sandbox design. This is the
  1540. 57:38playground design. So I selected all of
  1541. 57:40this and copied and pasted it back. So,
  1542. 57:41there are no problems right now. So,
  1543. 57:43honestly, I didn't think there was an
  1544. 57:44issue. But it's okay. Okay, we have
  1545. 57:47some more values here. Let's take those
  1546. 57:50as well. So look, we also have this
  1547. 57:52paragraph. A low and a high. We'll use
  1548. 57:53this as well. So we'll copy the query
  1549. 57:55section of this as well. That way we'll
  1550. 57:58tell the values whether this is a low
  1551. 57:59value or a high value. So we'll take
  1552. 58:02this and call it low and high. Low and
  1553. 58:07high. Okay? That's it. Okay, we'll take
  1554. 58:10one more thing here. Where is it
  1555. 58:15actually? Here it is. These result
  1556. 58:17paragraphs, we'll actually show all
  1557. 58:19these values to the user only when we
  1558. 58:21have, or what if we'll probably hide
  1559. 58:24these values here. We'll do all this.
  1560. 58:26So we're going to do all this work now.
  1561. 58:28If the user has taken all the guesses,
  1562. 58:29let's say, then we won't show them the
  1563. 58:31previous guesses, the remaining guesses
  1564. 58:33, etc. We'll tell them to start over.
  1565. 58:34So let's hold on to this for once. Then
  1566. 58:36we'll discuss what to do with it. So
  1567. 58:39here we go, and this is the class we
  1568. 58:42created. Okay. Here we have the class.
  1569. 58:45And we'll hold this in a variable for
  1570. 58:49the start-over. Okay? We'll provide the
  1571. 58:51start-over messages here. Okay. And
  1572. 58:54we'll insert some values. So, actually,
  1573. 58:56we'll take that too. Let's take a
  1574. 58:59paragraph because we're going to inject
  1575. 59:01it in several places later. Then I'll
  1576. 59:03tell you the strategy we're following.
  1577. 59:05document.createElement. Which element
  1578. 59:08do we create? Nothing, just create a
  1579. 59:10paragraph. Okay. Now let's talk about
  1580. 59:12the strategy: what exactly do we need?
  1581. 59:16So, let's take those variables. So,
  1582. 59:19first of all, we'll need a variable.
  1583. 59:21What will it be? It will be an array.
  1584. 59:22Okay? Why would it be an array? Because
  1585. 59:24what will we do inside it? Whatever
  1586. 59:26values the user submits, we'll store
  1587. 59:28those values and show the entire array
  1588. 59:31to the user so they know not to guess
  1589. 59:34the same guest value again. Okay? For
  1590. 59:36that, we've taken one. So, what we'll
  1591. 59:38need to track next is how many attempts
  1592. 59:41they've made. So, their number of
  1593. 59:43guesses, or let's call it num-guesses.
  1594. 59:46Number of guesses. We'll take that too.
  1595. 59:48We'll start with one, meaning this is
  1596. 59:49your first guess. Okay? We'll start
  1597. 59:51with one, and as soon as it reaches 10,
  1598. 59:53we'll block them, saying they can't
  1599. 59:55submit anymore, so we'll disable the
  1600. 59:57submit. Okay? We'll add a property to
  1601. 59:59that. Okay? And we'll also take a
  1602. 1:00:02variable here called let's play the
  1603. 1:00:05game. And what will we set to play the
  1604. 1:00:07game? true. Well, whenever you design
  1605. 1:00:09games like this, there's always a
  1606. 1:00:11variable called" playGame "that allows
  1607. 1:00:13you to play the game. Now, suppose your
  1608. 1:00:15events have completed, your coins have
  1609. 1:00:17been depleted, or something like that.
  1610. 1:00:19Nothing progresses without checking
  1611. 1:00:21this condition. This is how games are
  1612. 1:00:23designed. Okay? So, that's our basic
  1613. 1:00:26idea: we need these values, and that's
  1614. 1:00:28all we had to do, was collect and
  1615. 1:00:29prepare things. We haven't written any
  1616. 1:00:35of the code's logic yet. Okay? So now
  1617. 1:00:36we'll write a few functions and define
  1618. 1:00:39how they work. So, the first function I
  1619. 1:00:43need is" validateGuess. "So, what's
  1620. 1:00:46inside this" validateGuess "function?
  1621. 1:00:48Give me a guess, and I'll validate it.
  1622. 1:00:51Okay? So, why is this there? This is
  1623. 1:00:53because I first need to see if he
  1624. 1:00:55guessed a valid number or not? What if
  1625. 1:00:57he guessed A B C? Obviously. Next,
  1626. 1:00:59we'll check if the value is less than
  1627. 1:01:02one. Is he giving negative values? Or
  1628. 1:01:05because we created the game from one to
  1629. 1:01:07100. If he's giving a value of 500,
  1630. 1:01:08that's still not right. So, we'll do
  1631. 1:01:10all this validation of the guesses
  1632. 1:01:12within this method. Okay? Okay, sir? So
  1633. 1:01:15, this work is done within this method.
  1634. 1:01:18Now, what do we do next? After that, we
  1635. 1:01:22need another method called" CheckGuess.
  1636. 1:01:26"Here you go. Okay, you'll have to
  1637. 1:01:28enter your guesses within this"
  1638. 1:01:29CheckGuess "as well. Now you'll say,"
  1639. 1:01:30Well, it's validated. Why do we need to
  1640. 1:01:32check it now? "Look, the validation has
  1641. 1:01:35been done, but from there you only get
  1642. 1:01:36validation that the values are above or
  1643. 1:01:38below. We haven't been able to get it
  1644. 1:01:40to print any message. So what do we do?
  1645. 1:01:42We want to print a message to confirm
  1646. 1:01:44whether your value or the guest value
  1647. 1:01:46is correct, low, or high. So, the check
  1648. 1:01:49will happen here. Validation and check
  1649. 1:01:51are almost the same. You can give it
  1650. 1:01:53any other name if you want. This name
  1651. 1:01:54seems fine to me right now. So, what
  1652. 1:01:57else can we do? Because you're printing
  1653. 1:01:58that message in check guesses. So, if
  1654. 1:02:00you want, you can do it directly within
  1655. 1:02:01that. But what will I do? I'll create
  1656. 1:02:04another method here, which I'll call
  1657. 1:02:07displayMessage. So what will happen is
  1658. 1:02:11that as soon as there's a display
  1659. 1:02:12message in this method, you just pass a
  1660. 1:02:14message or your guess inside it, and
  1661. 1:02:16I'll send you the message directly.
  1662. 1:02:18What will this method do? It will
  1663. 1:02:20interact directly with the DOM. Okay?
  1664. 1:02:22So, we'll display the message. It's
  1665. 1:02:23very easy. We won't do anything else.
  1666. 1:02:25We'll empty the user's input value
  1667. 1:02:28again. Because obviously, he needs to
  1668. 1:02:30guess next. And what else will we do
  1669. 1:02:32with that? We'll add our guess to our
  1670. 1:02:35inner HTML. Okay? What else will we do?
  1671. 1:02:38We'll reduce your numbers. These
  1672. 1:02:41numbers mean all the manipulation of
  1673. 1:02:43the HTML DOM will be done within the
  1674. 1:02:44display message. Okay? So, this is our
  1675. 1:02:48display message. Okay? Okay, there's no
  1676. 1:02:50guess inside it. We'll actually take a
  1677. 1:02:52message from the user. Okay? Did I put
  1678. 1:02:55too many yeses? I put too many. Okay?
  1679. 1:02:59So, we'll take a message for the user
  1680. 1:03:01system and print whatever the message
  1681. 1:03:03is there. Okay, okay. That's enough
  1682. 1:03:07display messages, so let's create
  1683. 1:03:09another method that will do all the
  1684. 1:03:10rest. We'll tell it to display the
  1685. 1:03:12guess. We'll give it the display guess
  1686. 1:03:18method. And here we'll see there are
  1687. 1:03:20more methods like this. Okay? So, let's
  1688. 1:03:22summarize for now. In case you're a
  1689. 1:03:24little confused. What's the validate/
  1690. 1:03:26guess method supposed to do? It won't
  1691. 1:03:28do much. It simply guesses and
  1692. 1:03:30validates whether a value is between 1
  1693. 1:03:32and 100, and whether the value actually
  1694. 1:03:35exists. We'll use all of these methods
  1695. 1:03:37here, but that's the main role for now.
  1696. 1:03:39After that, we'll have a check/guess
  1697. 1:03:40method. The check/guess method will
  1698. 1:03:43check if the value is equal to the
  1699. 1:03:45random number. If it's equal, use this
  1700. 1:03:47display message to tell the player
  1701. 1:03:49you've won the game. If it's low, say
  1702. 1:03:51it's low. If it's high, say it's high.
  1703. 1:03:53And what happens within display/guess
  1704. 1:03:55is that this display/guess method won't
  1705. 1:03:56do anything. It will clean up your
  1706. 1:03:59values. Okay? Because you need to input
  1707. 1:04:01the next value as well. You don't need
  1708. 1:04:02to take the same value. What else will
  1709. 1:04:04it do besides update the arrays
  1710. 1:04:06containing your guesses. It will also
  1711. 1:04:08update your remaining guesses. And what
  1712. 1:04:10will the display message do? There
  1713. 1:04:11won't be much here. In fact, we've
  1714. 1:04:12taken the low and high values here.
  1715. 1:04:14We'll pass a message into this query
  1716. 1:04:16field and print that message as it is.
  1717. 1:04:19Okay? You've got it. Now we need a
  1718. 1:04:22method to determine what we want to do.
  1719. 1:04:24We want to end the game and start a new
  1720. 1:04:26one. Okay? So, here's the function.
  1721. 1:04:29What do you do first? Here's the new
  1722. 1:04:31game. We've got a new game. We've
  1723. 1:04:33started this new game. And here's a
  1724. 1:04:36function. This is called end game. So,
  1725. 1:04:39you've ended the game. Okay, sir.
  1726. 1:04:42That's a lot of methods. I told you
  1727. 1:04:43projects are a bit complex. And you
  1728. 1:04:45also wanted some longer videos. So,
  1729. 1:04:47okay. Okay, now we're done. This new
  1730. 1:04:50game, end game, these are very easy
  1731. 1:04:52methods. You can place it anywhere you
  1732. 1:04:54want. Let's do one thing: first, we'll
  1733. 1:04:56place the end game so you can
  1734. 1:04:57understand the flow easily. In fact, it
  1735. 1:04:59doesn't matter where you place the
  1736. 1:05:00method. But for the sake of
  1737. 1:05:01understanding, we can do the end game
  1738. 1:05:03and then start a new game. Okay? Now
  1739. 1:05:06let's talk about how these methods are
  1740. 1:05:08designed. First, check if you're even
  1741. 1:05:11available to play the game. Okay? How
  1742. 1:05:14do you check that? First, we'll check
  1743. 1:05:16the if condition. Here you have your if
  1744. 1:05:18method. Now, what's inside it? If it's
  1745. 1:05:20play, it will automatically evaluate to
  1746. 1:05:22true or false. If it is, play the game,
  1747. 1:05:24otherwise don't. So, if you can play
  1748. 1:05:27the game, what do you do? So, take this
  1749. 1:05:30submit we've taken. Remember this
  1750. 1:05:32submit here? I took this submit. So, I
  1751. 1:05:34need to listen to it. So, I need to add
  1752. 1:05:37an event listener here. Do I need to
  1753. 1:05:40add an event listener? It's very easy.
  1754. 1:05:42I need to add a click. And here's your
  1755. 1:05:45function. And here it is. Okay? Now,
  1756. 1:05:47inside this function, you know that you
  1757. 1:05:49get an event. Yes, we discussed it, so
  1758. 1:05:52here you have the event here. Okay? Now
  1759. 1:05:54, if you get an event, this is a form,
  1760. 1:05:56so what do you do with the form? The
  1761. 1:05:58values will be stored on the server, or
  1762. 1:05:59wherever someone is calling it. So, the
  1763. 1:06:01first thing you need to do is prevent
  1764. 1:06:03the event by default, saying," No, no,
  1765. 1:06:04don't take the values anywhere. Stop it
  1766. 1:06:05here, I'll take them here. "Okay? Now,
  1767. 1:06:08the second thing you need is this guess
  1768. 1:06:10number. Now, when we designed our
  1769. 1:06:14sectors, we took user input. We didn't
  1770. 1:06:17actually take that user input from the
  1771. 1:06:18user, right? We just selected it. So,
  1772. 1:06:22now we have to select its values. So,
  1773. 1:06:23it's very simple. What can we do? You
  1774. 1:06:25can write the user input dot value
  1775. 1:06:26there if you want. There's no problem
  1776. 1:06:28at all. But this value also needs to be
  1777. 1:06:30parsed as an int. Yes, you probably
  1778. 1:06:33forgot. Here, I've parsed it as an int.
  1779. 1:06:36Now what do you do with this value?
  1780. 1:06:37Hold it in a variable. Here. Here, I've
  1781. 1:06:42held it. Okay, is the game complete yet
  1782. 1:06:44? Look, I don't have to do anything. I
  1783. 1:06:46just have to pass it as it is to the
  1784. 1:06:48next one. Here, validate the guess. And
  1785. 1:06:51here, I've passed you the number. That
  1786. 1:06:53was all I had to do. Design in small
  1787. 1:06:55functions. So, my work is done. So,
  1788. 1:06:58this play if condition is done. Look, I
  1789. 1:07:00checked that the user was allowed to
  1790. 1:07:02play the game. After that, he entered a
  1791. 1:07:05number. I picked the number from here
  1792. 1:07:07and displayed it here. And if you want,
  1793. 1:07:10I can also lock the console to see if
  1794. 1:07:12the number is coming in correctly. So,
  1795. 1:07:15I've written this guess inside the
  1796. 1:07:16console lock. Okay? So let's try this
  1797. 1:07:18once and see if it's working. Suppose I
  1798. 1:07:21typed six here. I pressed submit and
  1799. 1:07:24guessed six. But obviously, I'm not
  1800. 1:07:25checking it right now. I've already
  1801. 1:07:28taught you how to select if it's empty
  1802. 1:07:30or not a number. I've already seen all
  1803. 1:07:31of that. So, repeating the same thing
  1804. 1:07:3310 times doesn't make any sense. So,
  1805. 1:07:36right now, I'm guessing whatever
  1806. 1:07:36numbers are there. So, my event
  1807. 1:07:39listener method is working fine for me.
  1808. 1:07:40Okay? That's all clear. Now, within
  1809. 1:07:42this validate guess, we'll check
  1810. 1:07:44whether the number is actually entered
  1811. 1:07:46correctly. You could have checked here
  1812. 1:07:48as well if you wanted. But since a
  1813. 1:07:49validate guess method has already been
  1814. 1:07:51described, let's apply validation. Look
  1815. 1:07:52, let me tell you one more thing.
  1816. 1:07:54You're going to write about these
  1817. 1:07:55validation methods a lot. Because what
  1818. 1:07:57happens? When you write about the
  1819. 1:07:58backend of any application, suppose a
  1820. 1:08:00username or an email address appears.
  1821. 1:08:02There are also specially created
  1822. 1:08:04methods to validate whether the email
  1823. 1:08:06contains an@, or whether there's a word
  1824. 1:08:09after the@? Is it already in the
  1825. 1:08:12database? Is the username a valid email
  1826. 1:08:13address? Is it a unique email address?
  1827. 1:08:15So, you'll be doing a lot of such
  1828. 1:08:16validations. Okay, so now we'll check.
  1829. 1:08:19So, first, let's check by applying an'
  1830. 1:08:20if condition '. Here you go. So, what's
  1831. 1:08:21inside the' if condition '? I told you,
  1832. 1:08:23' is not a number 'is a method nowadays
  1833. 1:08:25that checks whether it's a number or
  1834. 1:08:27not. So, since you've already got the'
  1835. 1:08:29guess 'here, here you go, you've got
  1836. 1:08:31the' guess 'and we'll set an alert.
  1837. 1:08:33Although I prefer that only a text
  1838. 1:08:34message goes there, okay, I don't want
  1839. 1:08:36to proceed further and let's make it a
  1840. 1:08:38little easier. So, let's give him an
  1841. 1:08:40alert message here: Please add and
  1842. 1:08:41please enter a valid number. Now, we're
  1843. 1:08:48going to use this method, this message,
  1844. 1:08:50in many places. Okay? What else would
  1845. 1:08:53you like to check? Let's do one more
  1846. 1:08:55check. Let's check one more time: is
  1847. 1:08:58our guess less than one? What if it's a
  1848. 1:09:04one-digit number? Copy this math here.
  1849. 1:09:06Okay, sir. There you go. That's it.
  1850. 1:09:09Okay, what can we do now? Duplicate it.
  1851. 1:09:12Here, copy it and paste it. What do you
  1852. 1:09:15want to check now? Is it greater than
  1853. 1:09:16100? Obviously, you'll check this too.
  1854. 1:09:18If it's greater than 100, we'll do it.
  1855. 1:09:20Please, we need a number. Please enter
  1856. 1:09:24a number. Let's send a good message.
  1857. 1:09:26Let's say less than 100 and write here,
  1858. 1:09:32please add, please enter a number a
  1859. 1:09:36more than one. Okay? It was very basic.
  1860. 1:09:40Okay, sir. That's it. So, if you've
  1861. 1:09:42checked all this, what would you like
  1862. 1:09:44to do next? So, you'll be in the else
  1863. 1:09:45case. Obviously, what would you like
  1864. 1:09:48first in the else case? First, I'd like
  1865. 1:09:50to see your number somewhere. After
  1866. 1:09:54that, let's push it into the array.
  1867. 1:09:57Okay? We gave you previous guesses. So,
  1868. 1:10:00let's push it inside the previous
  1869. 1:10:01guesses. So, we have previous guesses.
  1870. 1:10:05How do we push it inside the array?
  1871. 1:10:06Here, dot push. Here, and your guess is
  1872. 1:10:09done. Since he's still playing, you can
  1873. 1:10:11add his number. Well, at least you've
  1874. 1:10:14done the push. Now, that might be his
  1875. 1:10:16last attempt. This might just be his
  1876. 1:10:1910th attempt. I don't want to let him
  1877. 1:10:21do it after that. So, after validation,
  1878. 1:10:23I'll first have to check if his game is
  1879. 1:10:27over. So, how can I check if this
  1880. 1:10:30number is over? If you remember, we
  1881. 1:10:34used the number of passes," Number of
  1882. 1:10:35Gags. "I can check it through this. Yes
  1883. 1:10:37, of course, we can. If this number of
  1884. 1:10:40passes is incremented, because I've put
  1885. 1:10:42it in the global scope. Remember, we're
  1886. 1:10:44using scoping. I've put it in the
  1887. 1:10:46global scope. So, if his number of
  1888. 1:10:48passes is his 11th, we don't have to do
  1889. 1:10:51anything. You can also check for less
  1890. 1:10:54than or greater than 10. Greater than
  1891. 1:10:56equal to 10, whatever you want. It's
  1892. 1:10:58the same thing. Okay? So what do we do?
  1893. 1:11:01So, if it's equal to that, we'll have a
  1894. 1:11:04message. This display message first
  1895. 1:11:07makes the display guess once, ensuring
  1896. 1:11:09that whatever it displayed is actually
  1897. 1:11:11in its possession. So, we'll give the
  1898. 1:11:13display guess method. Now, how it
  1899. 1:11:15displays it isn't my concern right now.
  1900. 1:11:17Just get it displayed. After that,
  1901. 1:11:19we'll also get a display message. The
  1902. 1:11:20display message needs a message. So,
  1903. 1:11:22okay, yes. Let's give it a message as
  1904. 1:11:23well. So, we send the display message a
  1905. 1:11:25message with a back text saying," Game
  1906. 1:11:27Over. "Now, how it displays it is its
  1907. 1:11:30concern. Okay? And we'll also tell the
  1908. 1:11:32user the random number, because the
  1909. 1:11:34game is over now. Okay? So, let's tell
  1910. 1:11:37it. The random number was already there
  1911. 1:11:39, because it was already over. So, here
  1912. 1:11:44it is, and since it's in the global
  1913. 1:11:45scope, I can access the random number.
  1914. 1:11:46So, let's take this and move it aside
  1915. 1:11:48so you can easily see it. Okay? If it
  1916. 1:11:50was over, then we've checked another
  1917. 1:11:53condition: that we pushed that number.
  1918. 1:11:55Now his game is over, so display the
  1919. 1:11:57message to him and make him do this too
  1920. 1:11:59. What else can you do? End the game.
  1921. 1:12:02So, here's the end game. I don't know
  1922. 1:12:04how to end it. Not end, but end game.
  1923. 1:12:08End game, yes, here's the end game. So,
  1924. 1:12:10we've called end game. We'll see how it
  1925. 1:12:12ends later, we don't have that headache
  1926. 1:12:14right now. Okay, sir, that's enough
  1927. 1:12:16work. But if you're considering the
  1928. 1:12:18else case, meaning it's not at 11 yet,
  1929. 1:12:21or equal to 11, what can we do in this
  1930. 1:12:23else case? Obviously, now that it's
  1931. 1:12:25here, it's less than 11, because we're
  1932. 1:12:26not allowing it to be greater, we've
  1933. 1:12:28already checked that. If you want, you
  1934. 1:12:30can also check the range base to see if
  1935. 1:12:32it's between 1 and 10. You can also use
  1936. 1:12:33that, it's not a bad thing in this
  1937. 1:12:35logic. So, what should we do first? It
  1938. 1:12:37needs to display a guess. It needs to
  1939. 1:12:40display the guess under all
  1940. 1:12:40circumstances. It needs to be told that
  1941. 1:12:43you set this number and it's in your
  1942. 1:12:44guess list. Okay? So what do we do here
  1943. 1:12:47? Just give the guess. Look, the number
  1944. 1:12:48is already going into the guess list,
  1945. 1:12:50into an array within the list. But it
  1946. 1:12:52also needs to be displayed. Okay?
  1947. 1:12:54That's done. Now, what do we do next?
  1948. 1:12:55We need to check whether your guess was
  1949. 1:12:58correct. So what do we do? We pass that
  1950. 1:13:01method to the check-guess method. Now,
  1951. 1:13:03we won't use this display message right
  1952. 1:13:06now, because we were sure it would
  1953. 1:13:08display a message. But if we get into
  1954. 1:13:10the check-guess method, we don't need
  1955. 1:13:12to display the message right now. What
  1956. 1:13:14we need to do is display a message
  1957. 1:13:16inside the check-guess method, whether
  1958. 1:13:18the value you entered is actually
  1959. 1:13:19higher or lower. So, we'll decide that
  1960. 1:13:21there. Okay? So that's it for our
  1961. 1:13:24validated guesses. Okay, sir. Now let's
  1962. 1:13:26go to check guess. What do we do inside
  1963. 1:13:28check guess? Actually, we need to check
  1964. 1:13:30whether it's equal to the random value,
  1965. 1:13:32lower, or higher. Based on that, we're
  1966. 1:13:33going to display messages. Okay, sir?
  1967. 1:13:36So let's check. Let's enter our if else
  1968. 1:13:38case. So, here we have our if else.
  1969. 1:13:40Okay, sir? Now what do we do inside if?
  1970. 1:13:42First, what do we do? Inside if, we
  1971. 1:13:48check the guess. Yes, sir. You're
  1972. 1:13:50giving us the guess. So, is that guess
  1973. 1:13:52equal to our random number? Okay? If
  1974. 1:13:55it's equal to the random number, then
  1975. 1:13:56fine. That's it. It's the end of the
  1976. 1:13:58game. You guessed it all in one go. So
  1977. 1:14:01what do we do in that case? Call
  1978. 1:14:02display message and give it a message.
  1979. 1:14:06What message will it give saying," Did
  1980. 1:14:09you guess it right? "You guessed it
  1981. 1:14:12right? Okay, sir. You guessed it right.
  1982. 1:14:15And then play the end game, because now
  1983. 1:14:18he's understood, so what more can we do
  1984. 1:14:20? Okay? So play the end game. Okay.
  1985. 1:14:23What if it's not equal to the random
  1986. 1:14:25number? It's smaller than that. Okay,
  1987. 1:14:27sir. So let's check that too. If the
  1988. 1:14:30guess you gave us is less than the
  1989. 1:14:32random number, we'll still have to
  1990. 1:14:34display a message. So let's take this
  1991. 1:14:36display message. Copy and paste it. So
  1992. 1:14:40what should we call it? Number is low.
  1993. 1:14:43So what will we actually do? Instead of
  1994. 1:14:45saying" Number is low, "we'll say"
  1995. 1:14:48Number is too low. "We'll also create a
  1996. 1:14:50little confusion in the game. We won't
  1997. 1:14:51make it that easy. Just write" low "as
  1998. 1:14:53soon as it's less. Say" too low "so he
  1999. 1:14:55can try again. Okay. Okay, that's it.
  2000. 1:14:59Let's copy and paste it back. If it's
  2001. 1:15:02greater than the random number, then"
  2002. 1:15:06Number is too high. "Okay, sir. So, our
  2003. 1:15:10check validation is complete, and the
  2004. 1:15:12check guess is complete. Okay? And
  2005. 1:15:14we've also printed the message. Okay,
  2006. 1:15:16okay. Now, the actual thing we need to
  2007. 1:15:19do is display guess. Now, look, we've
  2008. 1:15:21used this display message in many
  2009. 1:15:23places, but what exactly is this
  2010. 1:15:24display guess doing? How do we want it
  2011. 1:15:26to display to the user? So, look, the
  2012. 1:15:28first thing we need to do within the
  2013. 1:15:30display guess is what will we do with
  2014. 1:15:32this display guess? We'll update the
  2015. 1:15:34value of the user input we've taken.
  2016. 1:15:37Now, what will we update it with? With
  2017. 1:15:39an empty string, so once you've
  2018. 1:15:41submitted the value, something is
  2019. 1:15:42definitely happening to the value after
  2020. 1:15:44submission. So, look, display guess is
  2021. 1:15:45running here as well. Display guess is
  2022. 1:15:47running here as well. So, we actually
  2023. 1:15:48need to clear the value. So, we have to
  2024. 1:15:50do this. So, we can also call it a
  2025. 1:15:52cleanup. We could also call this the
  2026. 1:15:53cleanup method instead of displaying
  2027. 1:15:54the guesses. Okay? That's done. But
  2028. 1:15:57what do we do now? We need to add an
  2029. 1:16:01inner HTML to this guess slot that we
  2030. 1:16:03took. Now, if you remember this guess
  2031. 1:16:07slot that we took, actually, just a
  2032. 1:16:11second. Actually, we need to look here
  2033. 1:16:13first. Let's show you this guess slot
  2034. 1:16:15that we took a second. What is this?
  2035. 1:16:18These are our gases. Okay? Now, where
  2036. 1:16:20are these gases coming from? These are
  2037. 1:16:22our gases. So, we want to add our inner
  2038. 1:16:25HTML to this. So, we've selected this
  2039. 1:16:27span that we took. Now, I want to add
  2040. 1:16:29some values to this span. Okay? That's
  2041. 1:16:32what I want to do. So, let's come here.
  2042. 1:16:34So, I took this guess slot. I took its
  2043. 1:16:35inner HTML. So, what do we do inside
  2044. 1:16:38this inner HTML? We'll keep adding. So,
  2045. 1:16:40plus equals, what do we need to add?
  2046. 1:16:43What are we going to do? We're going to
  2047. 1:16:44add a variable. So, take this dollar,
  2048. 1:16:47and inside it, let's take these values
  2049. 1:16:52and call it gas. So, whatever gas
  2050. 1:16:54values are there, it's not updating
  2051. 1:16:56them. It's just pushing them. Okay?
  2052. 1:16:59What else do we need to do? Besides,
  2053. 1:17:00we're already here. So, let's add our
  2054. 1:17:03number of gases to the number of gases.
  2055. 1:17:06This has to increase, right? Because if
  2056. 1:17:08you look carefully, this number of
  2057. 1:17:10gases that we have, we started at one.
  2058. 1:17:13But it should increase. When will it
  2059. 1:17:15increase? When you're cleaning up the
  2060. 1:17:17value that the user has given, its
  2061. 1:17:18value is gone, so clean up the value
  2062. 1:17:20and show that value here, add that
  2063. 1:17:22value, update it. But there's one more
  2064. 1:17:25thing to do. We change the values of
  2065. 1:17:26these remaining gases as well. Now, how
  2066. 1:17:28have we done renaming remaining gases?
  2067. 1:17:31So look, here we've written the
  2068. 1:17:32remaining gases as a separate text. But
  2069. 1:17:34inside this span, we've given the last
  2070. 1:17:36result here the value of 10. So
  2071. 1:17:38updating this is very easy. Once a
  2072. 1:17:40value has been updated, what do we do
  2073. 1:17:42simply? Take this remaining. What do we
  2074. 1:17:44do inside it? Let's take this inner h
  2075. 1:17:46TM l and calculate the values inside
  2076. 1:17:48this inner h TM l. So with the back
  2077. 1:17:50text. Okay, let's calculate the values
  2078. 1:17:52each time. Okay, let's calculate them
  2079. 1:17:53right here. So JavaScript allows us to
  2080. 1:17:55do that. So let's do that. Here's the
  2081. 1:17:57dollar sign. So, how do we calculate
  2082. 1:17:59this? Let's subtract all your gases
  2083. 1:18:03from 11. So, wet gases are obvious. Now
  2084. 1:18:07, you don't have to go from 11 to 0, so
  2085. 1:18:10what we'll do is subtract 11. Once
  2086. 1:18:12you've taken one, you're 10, so now
  2087. 1:18:14it's nine. We'll allow one value
  2088. 1:18:16directly, then you can also multiply it
  2089. 1:18:18by 10, as you see fit. 11 seems fine to
  2090. 1:18:20me, so if you're confused, just use 10.
  2091. 1:18:23It's no big deal. We'll check this
  2092. 1:18:25further. I'll put 11 in now, so 11
  2093. 1:18:28minus the wet gases, whatever value
  2094. 1:18:30comes out will be printed here. Okay?
  2095. 1:18:33That's it. If you want, you can also
  2096. 1:18:35call it' Clean Up Gas 'instead of'
  2097. 1:18:36Display Gas '. You might find that more
  2098. 1:18:38comfortable. So that's all done. Now
  2099. 1:18:40let's move on to our new method. Okay,
  2100. 1:18:42sir? What's the new method? This is the
  2101. 1:18:44display message. So, what's the display
  2102. 1:18:46message? If you remember, we took a
  2103. 1:18:48value here, low and high. What was it
  2104. 1:18:50doing? This low and high are simply a
  2105. 1:18:52paragraph with nothing inside. So,
  2106. 1:18:54simply, you need to print the message
  2107. 1:18:55inside this, and the message is already
  2108. 1:18:57being passed to you here. It's very
  2109. 1:18:59easy. What do you do? Take this, and
  2110. 1:19:01then take this, and say we want to add
  2111. 1:19:03a value to your inner HTML. What value
  2112. 1:19:05do you want to add? So, take this. Now,
  2113. 1:19:07what do you do inside this? Take the
  2114. 1:19:09background text and an H2 or H3,
  2115. 1:19:11whichever you prefer. Let's take an H3.
  2116. 1:19:15Let's take an H2. Let's take an H2.
  2117. 1:19:19Take this, and then print the values
  2118. 1:19:20inside this. So, what value do you want
  2119. 1:19:21to print? Everyone has already created
  2120. 1:19:22their message well. So, pass the
  2121. 1:19:24message as it is. There you go. You're
  2122. 1:19:27done. Okay? Now comes the end game and
  2123. 1:19:29the new game. So, we'll have to do the
  2124. 1:19:31end game as well. So, let's try this
  2125. 1:19:33once. Okay? So, hopefully, we've
  2126. 1:19:35refreshed it. So, suppose I enter three
  2127. 1:19:38here. Submit, guess. So it's saying the
  2128. 1:19:40number is too low, and our input has
  2129. 1:19:42been cleaned up. If I enter it here,
  2130. 1:19:45say, 99, and submit it, it's checking
  2131. 1:19:47it's 99 again. What's happening now?
  2132. 1:19:49Actually, there's a slight problem here
  2133. 1:19:51. So, you entered three first, then 99.
  2134. 1:19:53So, there's actually no spaces between
  2135. 1:19:55them. Okay? So, we've actually got this
  2136. 1:19:59plus equals guess under display guess
  2137. 1:20:01here, and we'll have to adjust it a
  2138. 1:20:04little bit. So what do we do here?
  2139. 1:20:06We'll add a little spacing after the
  2140. 1:20:08plus equals guess. You can also add a
  2141. 1:20:09comma if you want. But you'll do this
  2142. 1:20:11much debugging anyway. Okay? So, let's
  2143. 1:20:13try it again. Let's refresh it once. So
  2144. 1:20:15, let's enter three once and submit. So
  2145. 1:20:18, this three appears here. Now let's
  2146. 1:20:20give it 66. It's submitted. So, look,
  2147. 1:20:22now there's a little spacing. If you
  2148. 1:20:24don't like it, you can add commas or
  2149. 1:20:26anything else. I'm just using spaces
  2150. 1:20:28now because they seem to fit. If you
  2151. 1:20:30want, add more spaces. Okay? It'll be
  2152. 1:20:33easy. I've added four, and then I've
  2153. 1:20:35added 33, so this 33 is also coming up,
  2154. 1:20:38and I've added 22, and this is also
  2155. 1:20:40coming up. So, look, you can see the
  2156. 1:20:42entire list here. If you want to do
  2157. 1:20:44something else within this and within
  2158. 1:20:46the inner HTML, display it in a
  2159. 1:20:47paragraph, or display it with commas,
  2160. 1:20:48you can do that too. It's not a big
  2161. 1:20:50deal. Because plus equals, it will
  2162. 1:20:52never change. If you don't like it, you
  2163. 1:20:56want to do this with it, so save it and
  2164. 1:20:58try it too. I've added five. I submit
  2165. 1:21:00it and it shows five. Then I add six.
  2166. 1:21:03This is what you want. You want comma
  2167. 1:21:06values. I like commas better. It's up
  2168. 1:21:08to you. Look, these are small things.
  2169. 1:21:10There's no need to take up so much load
  2170. 1:21:12. Okay? So that's the basics. Okay. Now
  2171. 1:21:16let's focus on the end game and the new
  2172. 1:21:17game, because the user will keep
  2173. 1:21:18playing. So, we'll have to do the end
  2174. 1:21:20game, right? You already wrote here,"
  2175. 1:21:22Make it an end game, "but we've never
  2176. 1:21:24done an end game. So, let's discuss the
  2177. 1:21:26end game as well, how will the end game
  2178. 1:21:28be? So, what will it take to do the end
  2179. 1:21:30game? First, you'll have to create a
  2180. 1:21:33button. Okay? Now, what is a button?
  2181. 1:21:35We'll have a button. Come here a second
  2182. 1:21:39. So what will we do? Let's create a
  2183. 1:21:42new button here. Right now, it's just"
  2184. 1:21:44Submit. "But actually, we'll need a new
  2185. 1:21:46button on which we can create all of
  2186. 1:21:48this. If we're doing the end game,
  2187. 1:21:49we'll also have to give it the option
  2188. 1:21:50for a new game. So, let's do that first
  2189. 1:21:52. Yes, sir. So, what do we do now?
  2190. 1:21:56First, let's focus on our new game. On
  2191. 1:21:58the end game, sorry, not on the new
  2192. 1:22:00game. So, how do you do the endgame? So
  2193. 1:22:02, the first thing you should do is
  2194. 1:22:05clear all the input fields. If you're
  2195. 1:22:07doing the endgame, you'll have to clear
  2196. 1:22:08them. So, take the value in this user
  2197. 1:22:11input, and this is the value cleared.
  2198. 1:22:15That's it. There wasn't much difficulty
  2199. 1:22:16in this. Okay? Okay, the value is
  2200. 1:22:18cleared. Now, what should you do to
  2201. 1:22:20prevent users from adding more values
  2202. 1:22:23to this user input? So, how do you do
  2203. 1:22:25that? So, what should you do with this
  2204. 1:22:28user input? Set an attribute. So, we
  2205. 1:22:31know how to set attributes. Here, set
  2206. 1:22:32attribute, and we've discussed a lot
  2207. 1:22:34about set attribute. Which attribute
  2208. 1:22:36would you like to set within it? I'll
  2209. 1:22:38set only one attribute within it, which
  2210. 1:22:41will be disabled. Now, you can't set
  2211. 1:22:44disabled alone. Actually, key values
  2212. 1:22:47are set in pairs. Normally, if you type
  2213. 1:22:49a disabled word in the input, it
  2214. 1:22:51becomes disabled. But this is where you
  2215. 1:22:52might run into problems. So what should
  2216. 1:22:54we do? Don't add anything to that
  2217. 1:22:56second parameter. So, it's a key-value
  2218. 1:22:58pair. You're done. Okay? That's it. So,
  2219. 1:23:02this is our endgame. Now, we need to
  2220. 1:23:05add a start button as well. So what
  2221. 1:23:08should we do? Let's add a class' List '
  2222. 1:23:11to that paragraph we took at the
  2223. 1:23:13beginning. classList.add. Okay? What
  2224. 1:23:18class' List 'are we adding inside it?
  2225. 1:23:20Look, that class has no use. So, let's
  2226. 1:23:22add a button inside it. Okay? Then it
  2227. 1:23:25will start behaving like a button.
  2228. 1:23:27Because you've written the classes in
  2229. 1:23:28such a way that they behave like
  2230. 1:23:29buttons. Okay? That hasn't worked yet.
  2231. 1:23:31Now, we need to add an inner h TM l
  2232. 1:23:33inside that paragraph as well. Okay? So
  2233. 1:23:36take a paragraph and tell it to add
  2234. 1:23:39inner HTML. Okay? What inner HTML
  2235. 1:23:42should you add? You can add a paragraph
  2236. 1:23:45, a div, a span. Whatever you add, it's
  2237. 1:23:48not that big of a deal. So, what I want
  2238. 1:23:51to do inside it is select an H1. Here,
  2239. 1:23:54let's select an H1 or H2. The H1 will
  2240. 1:23:57be quite large. Here, here, I've taken
  2241. 1:24:00the H2. Now what do I need to do inside
  2242. 1:24:03this H2? Let me add an ID. Here, whose
  2243. 1:24:08ID should I use? New Game. Because
  2244. 1:24:10we'll use the same method for this
  2245. 1:24:12button in New Game as well. We don't
  2246. 1:24:14need to add four buttons. Okay? Let's
  2247. 1:24:16tell it to start new game. Since End
  2248. 1:24:18Game is done, it should get this button
  2249. 1:24:20as well. Right now, all these buttons
  2250. 1:24:21are just hanging in the air. They don't
  2251. 1:24:23have much significance right now. Okay?
  2252. 1:24:25Inside that paragraph, you added a
  2253. 1:24:28button and an inner HTML, okay? So,
  2254. 1:24:31that's it. Okay, sir. We're done with
  2255. 1:24:34that. Now, what do we do? If you
  2256. 1:24:35remember, we took a startover. Remember
  2257. 1:24:39this startover, which was the result
  2258. 1:24:40paragraph? So, we've taken the entire
  2259. 1:24:44result paragraph. Now, what do we do
  2260. 1:24:47inside this result paragraph? We'll
  2261. 1:24:48change it again within its inner HTML.
  2262. 1:24:50Actually, we'll append it. At first, I
  2263. 1:24:52was thinking of removing all the values
  2264. 1:24:54and doing that. But then I thought,
  2265. 1:24:56let's do something. Let's use
  2266. 1:24:58appendChild to add a new child inside
  2267. 1:25:00it. Okay? Which new child should we add
  2268. 1:25:02? Here, we've added the paragraph. Okay
  2269. 1:25:05, sir? Now the paragraph is easily
  2270. 1:25:06available inside it. Remember, the
  2271. 1:25:08paragraph was in global scope, so this
  2272. 1:25:09is the paragraph. So, we created an
  2273. 1:25:11element, but nothing was placed inside
  2274. 1:25:12it. Coming here, we placed it inside,
  2275. 1:25:15adding a class, a button, and a new
  2276. 1:25:17game ID. We also added it. Okay, sir.
  2277. 1:25:20That's all done. What do we do now?
  2278. 1:25:22This is the end game. And tell it to
  2279. 1:25:25start the new game after this. Okay,
  2280. 1:25:29fine. Now when will the new game start?
  2281. 1:25:32What do we do now? Okay, we forgot one
  2282. 1:25:33more thing here. Remember, nothing will
  2283. 1:25:35happen without this. This play game
  2284. 1:25:37also needs to be changed, because this
  2285. 1:25:39is what actually ends the game. So what
  2286. 1:25:41do we do with play game? Make it false.
  2287. 1:25:43Yes, sir. We forgot this. It was very
  2288. 1:25:45important. Okay? Now, whatever work is
  2289. 1:25:47left, run the new method. See how it
  2290. 1:25:49runs the new method. We're not worried
  2291. 1:25:51about this. Okay, sir. Now let's save
  2292. 1:25:53it. What do we do for once? Let's enter
  2293. 1:25:56the values here. Hopefully, we won't
  2294. 1:25:58guess the values. So we'll only give
  2295. 1:25:59small values. Submit this two. Submit
  2296. 1:26:02two again. Submit three. Submit four.
  2297. 1:26:07Five. So 1 2 3 4, that's five values.
  2298. 1:26:09Let's quickly give five more. Submit
  2299. 1:26:11eight. Submit seven. Here, let's give
  2300. 1:26:14seven as well. 1 2 3 4 5 6 7 8, so
  2301. 1:26:17let's give nine. And here, 10. Submit
  2302. 1:26:22this guess. Now your remaining guess is
  2303. 1:26:24zero. So zero means one, so let's give
  2304. 1:26:26one. Submit. So see what happened now?
  2305. 1:26:28Now I can't click here. It's not here.
  2306. 1:26:30All the values have come to you. The
  2307. 1:26:32remaining guess has reached -1. So
  2308. 1:26:34actually, I should have stopped at zero
  2309. 1:26:35. But that's fine. You're also getting
  2310. 1:26:37random values like it was 22 and start
  2311. 1:26:39a new game. Now how do I start a new
  2312. 1:26:41game? It's not possible to click here.
  2313. 1:26:43So here's the click event listener. Now
  2314. 1:26:44, you don't have to create an event
  2315. 1:26:45listener just on the button. You can
  2316. 1:26:47also add it to the H1. Event listeners.
  2317. 1:26:49So, the event listener. You have to do
  2318. 1:26:50the New Game thing. So far, our game is
  2319. 1:26:52running fine. Okay? We've come a long
  2320. 1:26:54way. So, what do we do first? Let's get
  2321. 1:26:56a reference to this button. Okay? So,
  2322. 1:26:59just do the same simple document.query.
  2323. 1:27:03What do we do inside the query sector?
  2324. 1:27:05We added an ID. You could also get it
  2325. 1:27:07from a class. But okay, let's get it
  2326. 1:27:08from the ID. So, what do we do here? We
  2327. 1:27:11have an ID. Which ID is it? New Game.
  2328. 1:27:14Okay, so there it is. Now, let's hold
  2329. 1:27:16it in a variable. So, let's call it a
  2330. 1:27:20New Game button. Now, look, a button
  2331. 1:27:22doesn't always have to look like a
  2332. 1:27:24button. It's possible that clicking on
  2333. 1:27:25H1 will look like a button. You can
  2334. 1:27:27change that in CSS if you want. Okay,
  2335. 1:27:29so what do we do now? You'll have to
  2336. 1:27:31listen to this" New Game "button that's
  2337. 1:27:33appeared. So, it's a simple story: add
  2338. 1:27:35an event listener. Okay, sir. Which
  2339. 1:27:37event should you listen to? Here,
  2340. 1:27:38you've already listened to the" click.
  2341. 1:27:40"What do you need to do? Let me explain
  2342. 1:27:42. Now, write the function. Here, take
  2343. 1:27:45this function. Here, take it. Okay?
  2344. 1:27:48What happens inside the function?
  2345. 1:27:49You'll get the event anyway. Okay? We
  2346. 1:27:51already have the event. Okay? Now, you
  2347. 1:27:53can use this event if you want. If you
  2348. 1:27:55don't, don't use it. This event doesn't
  2349. 1:27:57really matter because as soon as this
  2350. 1:27:59event happens, meaning the click, we
  2351. 1:28:01don't care about this event. We need to
  2352. 1:28:03reset our variables. Yes, sir. The main
  2353. 1:28:05story starts there. So, what should we
  2354. 1:28:07do first? What should we do first? Turn
  2355. 1:28:08on" Play Game. "So, set" Play Game "to
  2356. 1:28:11true. Your game starts there. But don't
  2357. 1:28:14use" Play Game "too quickly because
  2358. 1:28:16you'll actually reset all the variables
  2359. 1:28:18first. After that, you'll allow the
  2360. 1:28:21user. So what do you need to do? First,
  2361. 1:28:23you'll need to generate a new random
  2362. 1:28:25number. So, get a random number. Why do
  2363. 1:28:29you need to code it all over again?
  2364. 1:28:30Since we already know the random number
  2365. 1:28:31was generated this way, it would
  2366. 1:28:33actually be better if we changed it,
  2367. 1:28:35because re-creating the random number
  2368. 1:28:37would cause const problems. So, let's
  2369. 1:28:39change it now, and the logic will
  2370. 1:28:41remain the same. So, let's copy it and
  2371. 1:28:44move it here. So, random number equals
  2372. 1:28:47random number. Here, the random number
  2373. 1:28:49is generated. You don't need to remove
  2374. 1:28:52the previous guesses one by one. Just
  2375. 1:28:55reset it, it's done. Now, whatever
  2376. 1:28:58values you entered in the previous
  2377. 1:28:59guesses are empty. It's reset again.
  2378. 1:29:02Okay, sir. What do you do next? Start
  2379. 1:29:05your guessing numbers, that's it. Right
  2380. 1:29:07now, you're taking your first guess.
  2381. 1:29:09And what else can you do? The inner
  2382. 1:29:12HTML of the guess slot has also been
  2383. 1:29:15emptied. That disabled field will also
  2384. 1:29:18need to be removed. Remaining will also
  2385. 1:29:19need to be removed. Yes, sir. So, what
  2386. 1:29:21should we do with this remaining inner
  2387. 1:29:26HTML? Now, we can use the same logic we
  2388. 1:29:31used here. Yes, we can actually use the
  2389. 1:29:32entire remaining. Copy it, because the
  2390. 1:29:36upper value is already selected. So,
  2391. 1:29:39here it is, it's calculated again. Why
  2392. 1:29:41do we need to do it again? Yes, we need
  2393. 1:29:43to remove that from user input. We can
  2394. 1:29:46use the remove attribute here. Not
  2395. 1:29:48remove attribute ns, but remove
  2396. 1:29:50attribute. So, remove attribute, here
  2397. 1:29:55it is. Which attribute do we need to
  2398. 1:29:58remove? There's only one. Disabled.
  2399. 1:30:02We've removed this attribute as well.
  2400. 1:30:05What else do we need to do? If you
  2401. 1:30:07remember, we also had a start over.
  2402. 1:30:09Remember? Start over? No, remember? It
  2403. 1:30:10was start over. This query result pass,
  2404. 1:30:13the result pass we took, contains the
  2405. 1:30:15entire values. We appended a child here
  2406. 1:30:18. Yes, that's exactly what we need to
  2407. 1:30:19remove, so we'll have to remove one
  2408. 1:30:20child from here as well. Now, yes,
  2409. 1:30:22we're not just adding. So, which child
  2410. 1:30:26do we need to remove? We only have one.
  2411. 1:30:30Remove this paragraph. Okay? It will
  2412. 1:30:32get the reference to the paragraph
  2413. 1:30:33above. And then set" play game "to true
  2414. 1:30:36. Hopefully, your game will start. Okay
  2415. 1:30:39, sir. It was quite lengthy, but
  2416. 1:30:40interesting. We didn't do anything
  2417. 1:30:42complicated. We just went step by step.
  2418. 1:30:44Okay, sir. Let's play it one more time.
  2419. 1:30:46So, let's submit two. Then submit three
  2420. 1:30:49. Then submit 11, then submit 11 again.
  2421. 1:30:56Submit 22. Submit 33. Submit 44. And
  2422. 1:31:02submit 55. And too high. Okay? Okay? We
  2423. 1:31:07want to go high. We're not even looking
  2424. 1:31:08. We don't have to go that far. 77 and
  2425. 1:31:11another value, 88. Okay? That's all
  2426. 1:31:15done. The random number was 53. The
  2427. 1:31:17remaining value is negative one. You
  2428. 1:31:18can change that. That's all the
  2429. 1:31:20assignment for you. Let's start over.
  2430. 1:31:22So all the values are there again. I
  2431. 1:31:24can enter them again here. So, I saw, I
  2432. 1:31:26enjoyed the projects. They're quite
  2433. 1:31:28lengthy, but they're quite interesting
  2434. 1:31:29and fun. Let's copy this and move it to
  2435. 1:31:32our browser so we can give you this
  2436. 1:31:34code too. Let's come here. Hey, we're
  2437. 1:31:37done with the code. So let's start it
  2438. 1:31:42again. I hope you enjoyed it. There are
  2439. 1:31:46a lot of good projects in it. A lot of
  2440. 1:31:47projects, so I won't add any more right
  2441. 1:31:49now because I want to talk a little
  2442. 1:31:50about event listeners and a little bit
  2443. 1:31:51of JavaScript. I can't do any projects
  2444. 1:31:53based on the classes right now because
  2445. 1:31:54I haven't taught you the classes. I
  2446. 1:31:56can't discuss higher-order functions. I
  2447. 1:31:59can't discuss prototypes. I can't
  2448. 1:32:01discuss advanced topics. But obviously,
  2449. 1:32:03I'll take my time, but I'll teach
  2450. 1:32:05JavaScript in a way I never have to see
  2451. 1:32:07again. Okay, sir. So, just wait a
  2452. 1:32:09second, I'll give you the final code
  2453. 1:32:11and then I'll wrap up the video. In the
  2454. 1:32:13meantime, please subscribe to your
  2455. 1:32:14subscriptions and other things. And if
  2456. 1:32:16the video isn't getting shares on
  2457. 1:32:18Lindin even after so much hard work, it
  2458. 1:32:20means you're not enjoying the projects,
  2459. 1:32:22and I should just teach. I should do
  2460. 1:32:24fewer projects. Okay? So, this is our
  2461. 1:32:27Project 4 solution. Yes, please do it.
  2462. 1:32:30Subscribe in the meantime. If you say
  2463. 1:32:33you're leaving the video right now,
  2464. 1:32:34next time I'll leave the video right
  2465. 1:32:36here, and you won't find this code.
  2466. 1:32:39Tell me, are you done yet? Here you go,
  2467. 1:32:41your solution is ready. The Project 4
  2468. 1:32:43session is up, okay. So, let's have
  2469. 1:32:46some fun. Let's save it and commit it,
  2470. 1:32:51Project 4. Here we go, commit it, and
  2471. 1:32:57push it, so you get the source code.
  2472. 1:33:04And there we go, and refresh it and
  2473. 1:33:07check it. So, Project 1, 2, 3, 4, yes,
  2474. 1:33:10you have all the source code. So, go to
  2475. 1:33:13this code sandbox, Stack Blitz, and see
  2476. 1:33:16what numbers you have, what values you
  2477. 1:33:19have. Now, the best part is that I can
  2478. 1:33:23refresh it whenever I want, and all
  2479. 1:33:26this will disappear. So, here's our
  2480. 1:33:29code. Well, it's there for now, because
  2481. 1:33:32I have to open it in a new tab. But,
  2482. 1:33:34okay, your URL is saved here. You can
  2483. 1:33:36take a look at it if you want. The good
  2484. 1:33:38thing is that I can also see how many
  2485. 1:33:40of you are practicing this. I mean, it
  2486. 1:33:42doesn't come to the individual exactly.
  2487. 1:33:44But yes, if I tell you here, then these
  2488. 1:33:46projects of Dom, then here I can see
  2489. 1:33:48all these things like project views
  2490. 1:33:50etc. If we go back to this, then how
  2491. 1:33:52many projects are there here? How many
  2492. 1:33:54views are there on that? All this is
  2493. 1:33:55visible. So how many fors have there
  2494. 1:33:57been? How many views have there been?
  2495. 1:33:58So all this is also visible. Well, it
  2496. 1:33:59felt good. I hope that the effort that
  2497. 1:34:01we have put in, the hard work that we
  2498. 1:34:02have done, will be very useful for you
  2499. 1:34:04too. If you want more such videos which
  2500. 1:34:06are purely project based, then tell me
  2501. 1:34:07in the comment section, we will bring
  2502. 1:34:09more videos. Well, it has been quite
  2503. 1:34:10late. See you in the next video.

About this transcript

This page contains the full transcript of Lets build 4 javascript projects for beginners | chai aur #javascript by Chai aur Code, generated from the public captions YouTube serves with the video. The transcript has 18,181 words across 2,503 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.