JavaScript Chapter 3 - Practice Set on Loops and Functions | JavaScript Tutorial in Hindi #12
Aug 15, 2023
JavaScript Chapter 3 - Practice Set on Loops and Functions | JavaScript Tutorial in Hindi #12
This video is about some practice questions on loops and functions in JavaScript Link to the Repl - https://replit.com/@codewithharry/12C … Join Replit - https://join.replit.com/CodeWithHarry Download Notes - https://drive.google.com/drive/folder … Ultimate JS Course Playlist: • JavaScript Tutorials for Beginners in… ►Checkout my English channel here: / @programmingwithharry ►Instagram: www.instagram.com/codewithharry python, C, C++, Java, JavaScript and Other Cheetsheets [++]: Playlist: • Coding CheatSheets 🧾 by CodeWithHarry ►Learn in One Video[++]: Python[15 Hr] - • Python Tutorial For Beginners In Hind… Python Advance[3.5 Hr] - • Python Programming Course in Hindi (A… Python[1 Hr] - • Learn Python In Hindi In One Video - … Python[2 Hr] - • Python Tutorial In Hindi 🔥 Python[15 Min] - • 15 Minute Python Tutorial For Beginne… JavaScript[1 Hr] - • JavaScript Tutorial C[1.3 Hr]- • C Programming Tutorial For Beginners:… php[1 Hr] - • Learn Php In One Video In Hindi - हिं… php[2.3 Hr] - • Php Tutorial for Beginners in Hindi w… php[Project]- • Login And Registration Form Using Php… HTML[30 Min] - • HTML 5 Tutorial For Beginners In Hind… CSS[8.5 Hr] - • CSS Tutorial In Hindi (With Notes) 🔥 CSS[1.4 Hr] - • CSS 3 Tutorial For Beginners: Learn C… Wordpress[3.2 Hr] - • How To Make a WordPress Website | Wor… Angular[2 Hr] - • Angular Tutorial in Hindi Java[2.3 Hr] - • Java tutorial in hindi 🔥 Web Scraping[1 Hr] - • Web Scraping Tutorial using Python an… MongoDB[2 Hr] - • MongoDb Tutorial For Beginners in Hin… Numpy[1 Hr] - • Numpy Tutorial in Hindi Android Dev[12 Hr]- • Android Development Tutorial For Begi… Linux[1 Hr] - • Linux Tutorial For Beginners in Hindi JQuery[1.1 Hr] - • jQuery Tutorial For Beginners In Hind… Git and GitHub[1.1 Hr] - • Git \u0026 GitHub Tutorial For Beginners I… ►Complete course [playlist]: React - • React Js Tutorials in Hindi Python- • Python Tutorials For Absolute Beginne… OOP Python- • Object Oriented Programming Tutorials… Java - • Java Tutorials For Beginners In Hindi JavaScript- • JavaScript Tutorials In Hindi PHP- • PHP Tutorials in Hindi C- • C Language Tutorials In Hindi C++- • C++ Tutorials In Hindi Git \u0026 GitHub- • Git and GitHub Tutorials In Hindi Android Dev- • Android Development Tutorials in Hindi Python GUI- • Python GUI: Tkinter Tutorial In Hindi… Web Development- • Web Development Tutorials For Beginne… Python Django - • Python Django Tutorials In Hindi Projects Using HTML, CSS \u0026 Javascript- • Projects Using HTML, CSS \u0026 JavaScript… Data Structure and Algo - • Data Structures and Algorithms Course… Follow Me On Social Media ►Website (created using Django Rest \u0026 Angular) - https://www.codewithharry.com ►Facebook - https://www.facebook.com/CodeWithHarry ►Instagram - https://www.instagram.com/codewithharry/ Twitter - https://twitter.com/CodeWithHarry Comment “#HarryBhai” if you read this 😉😉
Content
0.001 -> In today's video, we are going to see some
practice questions
3.867 -> on loops and function
6.366 -> We will go to the computer screen
7.724 -> and will see how various loop types work.
10.277 -> while loop, do-while loop, for loop,
for in loop, for of loop.
12.937 -> We will see all these types of loops.
14.715 -> And will solve some questions.
16.77 -> Let's move on to the computer screen
and let’s get started.
25.861 -> So guys we will see the practice set of
chapter 3
28.227 -> We will see some questions
29.766 -> That will help us in solidifying our
concepts from chapter 3.
34.424 -> So, let's us quickly create a Repl
using Node.js.
38.047 -> And here, simply I will write
the video number, which is 12th.
44.039 -> Alright! I will write Node.js.
Then I will write "12_Chapter3 PracticeSet".
52.229 -> And, will do create Repl.
54.228 -> Let us look at the first question.
Repl will be created by itself.
57.776 -> Learn to work in parallel!
59.149 -> Like finish your work,
shift to the next one and continue.
61.569 -> The point is to save time.
63.356 -> Write a program to print the marks of
a student in an object using for loop.
68.267 -> Object are something like this.
and you just have to print the marks.
71.939 -> You have to show the marks
in a human readable form.
75.675 -> So, I will do this question in this way.
77.833 -> First I will write "let obj is equal to"
80.176 -> And second thing is that whenever you
are giving a name to a variable,
84.01 -> no matter which programming language,
use my name!
89.001 -> Kidding! Don't use my name.
90.693 -> Use such names that help you understand
the function of the variable.
96.312 -> Neither my name nor your name.
98.333 -> For example, "marks". It clearly say
that marks are there inside "marks".
102.149 -> Suppose, harry's marks is 90.
105.082 -> subham's marks is 9.
Sorry Subham!
111.294 -> lovish's marks is 56.
116.085 -> And, Monika got 4 marks!
123.553 -> Now, I have to print it. Alright!
125.37 -> So, I can use for loop and write
"for let i is equal to 0
130.47 -> i
141.5 -> Now, I will tell you about "marks" and
"dot length"
143.603 -> And this is something that will
make you feel weird.
146.367 -> Now, "object.key marks.length" will give you
the length and the keys that are inside the object.
154.266 -> That means, how many keys are there in
this object.
157.226 -> So, if I print "object.keys marks",
all they keys will come in an Array.
161.456 -> We will learn about Array next.
163.1 -> But let me tell you that
Array is the collection of items.
165.84 -> So, selected harry, shubham, lovish,
and monika, all will come inside this.
169.737 -> If I put "length" after that,
4 will come.
171.834 -> Now observe, I will simply print it.
176.718 -> I will write
"console.log the marks of+object.keys marks i"
189.14 -> Alright!
189.983 -> And this syntax may look like
really weird to you.
193.919 -> But, that's the way to print marks
through "for loop"
196.838 -> But I have to just towards the concept
199.567 -> But I will tell you what do
"for in loop" and "for of loop" solve.
203.258 -> So, here is "marks of" and
I wrote "are"
206.773 -> After that I will write "+" and I will put
the object keys inside marks.
218.717 -> So, here the key will come.
220.146 -> So, this way it will be printed.
let me show you by running.
224.05 -> The way I will run this program.
225.688 -> Now see, the marks of harry are 90.
shubhan are 9, lavish are 56
229.82 -> 4 for Monika.
230.678 -> You may ask how does it work.
what is "object.keys"?
233.066 -> See, "object.keys marks" are giving us
all the keys.
236.518 -> Like "object.keys marks" will give us
harry, shubham, lovish, monika.
240.518 -> You can take this question as
a sample of Array.
245.828 -> So, "object.keys marks" will return.
248.253 -> Inside the array is the the collection of items.
250.587 -> like harry, shubham, lavish and monika.
252.474 -> If I out 0 here, then I will get "harry"
256.982 -> Index starts from 0.
258.823 -> If I put 1, then it will come as "subham".
260.851 -> With 2, "lovish"; with 3, "monika".
263.947 -> "i" is running from 0 to 4.
Because keys are 4 here.
267.668 -> Now you may think what is going on!
270.256 -> If you think so, we will do Array
in upcoming videos.
274.636 -> So, if you have this question,
that should be totally fine.
278.683 -> Everything will make sense to you
when we see "Array,"
281.983 -> Then I will tell what
this syntax is doing.
284.578 -> What will occur if I place any keys
inside of the marks?
287.671 -> I will get the value.
290.253 -> So, whenever I am using
"marks" and this syntax,
292.651 -> it will display the responding value of the
keys I have inserted.
295.928 -> In this case, I am doing
"object.keys marks"
298.946 -> which means all the keys.
300.319 -> Which keys that I require.
302.478 -> 0, 1, 2, and 3,
all the iteration of for loop.
305.623 -> So, this way syntax prints it.
308.068 -> So, this was the problem number 1.
311.723 -> Problem No. 1.
312.985 -> And I didn't have another way to print it
by using "for loop"
317.933 -> Now see how to use "for in loop".
320.133 -> Suppose I use "for in loop"
325.333 -> If I use "for in loop", then I can do
it this way.
328.374 -> I will copy and paste it just
for convenience.
330.946 -> So I will write hare "let i in marks"
335.755 -> And for once, I want to print
"console.log i" and show it to you.
343.001 -> So, whenever I do it,
345.253 -> it will print what is written up there
and the keys as well..
348.767 -> As I got the keys,
I will get the value as well.
351.34 -> Now see, how for in loop solves
such big problems.
353.744 -> Earlier, long code has to be written in
JavaScript.
357.033 -> Now you can do this.
359.186 -> Then you can write "marks of i are marks i"
Alright.
367.615 -> And I would say,
instead of "i", lets call it "key"
373.388 -> We were using "i" previously.
So, let's make it "key"
376.309 -> Remember I told you to use my name
in variables?
378.993 -> Sorry!(kidding)
379.953 -> Always use a name that makes sense
of the particular thing.
385.9 -> So, here the "marks of key" and
"are marks key"
389.4 -> So, this will print exactly which is
printed up there.
391.7 -> So, if i even comment out it here,
like this way.
396.869 -> Suppose I comment out and run this.
Then you can see.
400.187 -> What were being printed earlier,
the same thing is getting printed.
402.861 -> Let's move on to the next question.
404.821 -> Write a program to print "try again" until
the uses enters the correct number.
408.528 -> Suppose there is a correct number.
410.77 -> Let me comment out this and
remove this also
414.84 -> Suppose there is a correct number.
Alright!
420.048 -> Let me write the Problem No 3.
423.033 -> Suppose, I write "let cn is equal to 4".
Alright!
428.018 -> Now I will tell the user to enter
correct number.
432.071 -> Enter a number. And I will do "let i"
435.833 -> And I am asking the user to enter a number.
Alright!
438.425 -> So, I will write "prompt enter a number"
442.2 -> So, "I" will become "prompt enter a number"
447.273 -> And till the time "i" is not equal
to the correct number,
451.143 -> We will make the user to continue
entering.
454.333 -> Are you getting it?
455.833 -> We'll make the user to hang on entering.
Let's see how it works!
460.448 -> Suppose here I print 3, 6,7, and 4 as well.
470.32 -> So, Yeah!
471.345 -> I will write
"console.log you have entered a correct number"
477.903 -> Now, How this program is working?
479.002 -> Suppose the correct number is 43.
482.121 -> I ran this program.
483.725 -> Whatever I print after starting this
program will continue to print.
491.224 -> But, as soon as I write 43,
it will print "you have entered the correct number"
495.281 -> And the program will exit.
496.533 -> So, How it is working.
498.191 -> Very first, the correct number is 43,
which I have created already.
500.814 -> And I made a variable named "i"
503.119 -> and I said that till the time "i" is
equivalent to the correct number,
506.733 -> continue to take input from the user.
510.328 -> And this thing will continue.
512.344 -> "while i is not equal to correct number"
will continue.
514.533 -> As soon as "i" will be equal to the
correct number,
518.433 -> this program will be terminated and it will
not ask you for prompt anymore.
522.4 -> So, this program will continue till the
time you enter the correct number.
525.767 -> And that's the work we had to.
Alright!
528.343 -> And here we had to print try again as well.
534.518 -> "try again". Alright!
536.407 -> And it is written in the question to
print "try again"
539.82 -> until the user enters the correct number.
544.066 -> Now observe, the moment I wrote 43,
548.429 -> (Aah! Why it is showing "try again"!)
You have entered a correct number.
552.146 -> The moment I wrote 43
554.948 -> Actually,
let me do it this way!
560.662 -> And I will run it.
564.159 -> 4, 5, 6, and
566.667 -> The moment I write 43, it will print as
"you have entered the correct number."
571.109 -> So, I hope You guys have understood
the question and how we did this.
574.911 -> The 4th question is on function
and it is saying that
576.833 -> you have to write a function to
find mean of 5 number.
581.4 -> Let's solve this as well.
582.914 -> This was our question No. 3.
Now we will see the Problem No. 4.
587.596 -> And what's there in the Problem No. 4?
590.406 -> Well, we have to find out the mean.
591.711 -> So, what I will do is,
594.033 -> I will write "Arrow" function.
595.633 -> And I told you earlier that
I will always prefer "Arrow" function.
600.415 -> So, what I will do is,
602.717 -> Something like this way.
604.531 -> I will write an "Arrow" function.
Alright!
608.126 -> I will write these 4 numbers
a, b, c, and d. Alright!
614.785 -> And I will right the return in a shortcut.
617.165 -> "a+b+c+d"
622.463 -> divided by 4. Cool!
624.841 -> Now, if I write "console.log mean of 4, 5, 6, 7"
And run it.
633.496 -> Actually, this program is still running.
635.776 -> Let me quit this by writing 43.
638.848 -> See, it has given me the mean that is 5.5.
641.343 -> Is this correct?
644.606 -> What were my numbers?
646.576 -> I guess my numbers were
4, 5, 6, and 7. Let's see.
652.913 -> 4+5+6+7
657.168 -> It is pretty visible that the mean is 5.5.
660.231 -> Because the number that rely in them is 5.5.
667.553 -> I will do 22/4. And the result is 5.5,
which is correct.
671.266 -> So, I hope You guys have understood this
practice set.
673.363 -> And you will be able to
solve these questions..
676.925 -> We will see more concepts in the
next chapter
679.268 -> We will understand these concept with
more clarity.
682.181 -> Also we have completed 1 lakh views
on play list.
686.2 -> I not sure whether 1 lack people have
watched or the update itself is like this.
689.678 -> Let me know your thoughts on the comment.
691.767 -> It's unlikely that exactly 1 lakh
people have viewed.
694.615 -> I have seen 1 lakh and 1, 1 lack and 2 .
700.1 -> If you haven't bookmarked the
play list yet, then do it .
704.267 -> and save the play list as well.
706.585 -> That's it for now, guys!
708.26 -> Thank you so much for watching this video.
And I will see you next time!
Source: https://www.youtube.com/watch?v=ZAOipfPnb3s