JavaScript Chapter 3 - Practice Set on Loops and Functions | JavaScript Tutorial in Hindi #12

preview_player
Показать описание
This video is about some practice questions on loops and functions in JavaScript

python, C, C++, Java, JavaScript and Other Cheetsheets [++]:

►Learn in One Video[++]:

►Complete course [playlist]:

Follow Me On Social Media
Comment "#HarryBhai" if you read this 😉😉
Рекомендации по теме
Комментарии
Автор

I am a bit late here, just wanted to say ur tutorials are awesome thanks for helping me follow my passion. Also wanted to add a bit that in the problem no.3 u can see that everytime u execute it says try again first than asks user for a number. U can over come that by nesting an if else statement in while loop. i tried it and works like a charm. Here is the code :
let n = 4
let a
while(a != n)
{
a = prompt("Enter a number")
if(a == n)
{
console.log("You wrote correct number")
}
else {
console.log("Try again")
}
}

hokorashi_
Автор

The video's intro and outro was very good . the video quality is also good, the concepts are best . in all round case . I will rate this course a console.log( '5/5' )

manvanthmn
Автор

This Code can also be run by this :
Let obj = {
Harry:90,
Shubam:95,
Anika:96
}
for (let a in obj){
console.log(a);
console.log(obj[a]);
console.log("Marks of " +a+ " are " + obj[a]);
}

masaudhusnainathar
Автор

9:16 you can do it like this =>

let cn = 4
let i;
while(i!=cn){
i = prompt("Enter a number")
if(i==cn) {
console.log("You have entered the correct number")
}
else {
console.log("Try again")
}
}

Yenoke
Автор

Very amazing tutorials!
I'm enjoying learning with you as always!
We're lucky to have Harry in the world of programming who provides top notch quality content for free

learner
Автор

Harry Bhai the best teaching.. learning Javascript with is really amazing... Enjoying this series

MSajjad
Автор

🎯 Key Takeaways for quick navigation:

00:00 🔄 *In today's video, the instructor introduces practice questions on loops and functions in JavaScript, covering various loop types like while, do-while, for, for-in, and for-of loops.*
- Introduction to practice questions on loops and functions in JavaScript,
- Explanation of different loop types including while, do-while, for, for-in, and for-of loops.
01:03 💻 *The instructor demonstrates writing a program to print the marks of students stored in an object using a for loop, emphasizing meaningful variable naming and understanding object keys.*
- Writing a program to print student marks stored in an object using a for loop,
- Emphasizing meaningful variable naming and understanding object keys.
04:52 🔄 *Explaining the use of for-in loop as an alternative to for loop for iterating over object keys and values, highlighting the simplification of code compared to traditional for loops.*
- Introducing the for-in loop as an alternative for iterating over object keys and values,
- Highlighting the simplification of code compared to traditional for loops.
06:50 🔁 *Demonstrating a program using a while loop to continuously prompt the user to enter a number until the correct number is provided, showcasing the concept of looping until a condition is met.*
- Illustrating a program using a while loop to continuously prompt user input until a condition is met,
- Demonstrating the concept of looping until a condition is fulfilled.
09:54 📝 *Solving a problem to find the mean of five numbers using an arrow function, emphasizing the preference for arrow functions and demonstrating concise code for calculation.*
- Solving a problem to find the mean of numbers using an arrow function,
- Demonstrating the preference for arrow functions and concise code for calculation.- 00:00 🔄 Overview of Practice Questions
- Solving practice questions on loops and functions.
- Exploring various loop types: while loop, do-while loop, for loop, for in loop, for of loop.
- Demonstrating how to solve questions to solidify concepts from chapter 3.
01:03 🔄 *Printing Student Marks Using a For Loop*
- Using a for loop to print the marks of students stored in an object.
- Demonstrating how to iterate over object keys to access and print values.
05:25 🔄 *Using For-In Loop to Print Student Marks*
- Utilizing the for-in loop to simplify printing object key-value pairs.
- Demonstrating how for-in loop can simplify iterating over object properties.
06:50 🔄 *Creating a Loop to Prompt User Until Correct Input*
- Implementing a loop to continuously prompt the user until the correct number is entered.
- Using a while loop to keep asking for input until the correct value is provided.
09:54 🔄 *Calculating Mean of Numbers Using an Arrow Function*
- Defining an arrow function to calculate the mean of five numbers.
- Using a concise arrow function syntax for mean calculation.

Made with HARPA AI

Hafijur
Автор

Code with harry is helping many peoples in free .
It is really amazing ....

sandeepsolanki
Автор

Harry Bhai love from whole world
God Bless You chote bhaiyo ki Dua hai apke sath 🤲🤲🤲
@CodeWithHarry Harry Bhai videos please jaldi jaldi upload karo kyuki ek leh banne k baad ruka nahi jata fir leh toot jati hai.
and roz repeated videos dekhna pdta hai. na chahke bhi revision krna padta hai 😂🤣🤣

MohammedHusainmobikira
Автор

Maza aagya harry bhai bas aise hi knowledge baante rho.

sagarpanwar
Автор

Hi Harry,
Syed here from Indonesia
it's amazing
Thanks for sharing javascript course.

let cn = 4
let i
while(i !=cn){i=prompt("kindly enter the correct number")

if (i !=cn ){alert(" you entered wrong number")}
}
console.log("You enter the correct number")

findsyed
Автор

1:22 Very amazing tutorials!
I'm enjoying learning with you as always!

taniyaverma
Автор

The first question was actually very difficult to understand for a beginner

MuhammadUsamaQamar
Автор

Thank you, Harry, you have helped me a lot with these courses. May God bless you with success....😘

motivational
Автор

In problem 3, we have to convert our input data type into int bcoz it takes input as a string, which maybe results in an error(in VS code). It happened to me 😅. I used the following code to resolve it. Hope it will help someone else too


let cn = 4;
let i;
while (i != n){
i = parseInt(prompt("Enter a number:")
}
console.log("You have entered the correct number")



Thank you so much bro for these tutorials ❤❤

purnimavats
Автор

Excellent questions, Harry bhai. Level badha diya aapne...

I solved #3 like this:

const cn = 4;

while (parseInt(prompt("Input the correct number: ")) != cn) {
console.log("Try again!");
}

console.log("You entered the correct number.");

abdulquadir
Автор

To remove the try again during the start in problem 3, it's better to use if else. Like this

let cn ="Harry Bhai";
let i
while(cn != i){
i =prompt("Who is the Best Youtuber")
if(i !=cn){
console.log("Galat Zabab, Try again")
}
else{
console.log("Correct Answer")
}
}

wonderfullife
Автор

Foe question 3 this code can also be used...
let cn = 43
let i
while (i != cn) {
i = prompt("Enter a number")
if(i != cn){
console.log("Try again")
}
}
console.log("You have entered the correct number")

vaibhavtripathi
Автор

All Programs, Thank You Harry Bhai ❤❤❤
// Practice Question 1 & 2- write a program to print the marks of a student in an object using for loop
// Using for..in loop
let marks_1 = {
Harry:98,
Rohan:70,
Aakash: 7

}

for (const x in marks_1) {
console.log(`The Marks scored by the student ${x} is : ${marks_1[x]}` );

}

// Using for loop - CWH Lec
let marks_2 = {
Harry:98,
Rohan:70,
Aakash: 7

}

for (let i = 0; i < Object.keys(marks_2).length; i++) {
console.log(`The Marks of ${Object.keys(marks_2)[i]} is

// Object.keys(marks_2)
// Returns an Array with the keys as value

// Object.keys(marks_2).length
// Returns the length of the Array (4)

// Object.values(marks_2)
// Returns an Array with the values as value

//
// Returns the corresponding value of the key in the object (Alternate method to print values)

}

// Practice Question 3 - write a program that prints "Try again" until user enters the correct number
const prompt = true});
let CorrectNumber = 5;
let i;
while(i != CorrectNumber){
i = prompt("Enter a Number ");
console.log("Try Again"); // flaw - Prints "Try again" even when entered the CorrectNumber
}
console.log("You have entered the correct number");

// Practice Question 4 - write a function to find the mean of 5 numbers

let a = prompt("Enter any Number ");
a = Number.parseInt(a);

let b = prompt("Enter any Number ");
b = Number.parseInt(b);

let c = prompt("Enter any Number ");
c = Number.parseInt(c);

let d = prompt("Enter any Number ");
d = Number.parseInt(d);

let e = prompt("Enter any Number ");
e = Number.parseInt(e);

function MeanNumberFinder(a, b, c, d, e){
return (a + b + c + d + e) / 5;

}

console.log(MeanNumberFinder(a, b, c, d, e));

vickys
Автор

A different approach to get average for any number of arguments:
function multiple(...arguments){
let a=arguments;
let b=a.length;
let sum=0;
for(let i=0;i<b;i++){
sum=sum+a[i];}
return sum/b}
multiple(5, 6, 7, 8, 9, 10);

Abhilash_Nanda