A simple explanation that I always think about is "Math.random() sirf 0 se 1 tk random number generate krta hai 0 is inclusive, 1 is exclusive....So in this statement Math.random() * 10, the result can never be equal to 10 qki 10 lane k lie usko 1 se mulitply hona pdega jo ki possible nahi hai, to result hmesha 10 se niche hoga (it could be 9.999999) but 10 nhi hoga, or iske upr se agar aap Math.floor(Math.random() * 10) krte ho to result 0 se 9 tk koi bhi integer ho skta hai but 10 nahi, to 10 ko bhi range me include krne k lie hum usme 1 add kr dete hai.....that is if you do Math.floor(Math.random() * 11) to result [0,10] tk aaega both inclusive.....and at last isme bas aap 1 add kr doge to result [1,10] m convert ho jaega.... similarly, is concept ko max min m bhi leke jaa skte hai
22:29 actually here , the plus one is added to include the maximum number(20) into the range .. Zero case is already handled by adding +min after it ... For example let's say the random returns 0.99999 then multiply it with 11(20-10+1).. , we will get 10.989.... take the floor value of this which will be 10 and now add it with min value which is 10 so overall answer would be 20(the ending range). That's the maximum case.. Similarly if random returns 0.0122... then everything will get 0 in the left and then adding min(10) to 0 will give us 10 which is the starting range..
When we participate in the growth of others, we often end up growing ourselves first. You have done a lot for coders and continue to do so, which is great. I am eager to watch the complete Python course that is currently ongoing. However, I am very busy working on my clients' projects. In my remaining time, I am learning more about JavaScript to improve my knowledge. Although I already know JavaScript, learning from you is both fun and fortunate for me. Thanks for all you are doing !
Formula for generating random number : Math.floor(Math.random() * (total no. in the range)) + min_number For example : if you want to generate random number between 0 to 10, then min no. is 0, max no. is 10, total no. in the range is 11 ( max - min + 1), now putting to formula : Math.floor(Math.random() * (11)) + 0
sir your ability to convey intricate JavaScript concepts in a way that's both approachable and engaging is truly commendable, making us true asset to the learning community."
literally you're savour i singed up for ibm Frontend development on crousera although that's expensive and paid course but cloud not understand anything and came back to this series
Thank you for making such a beautiful javascript tutorial. Because You teach the actual javascript which is necessary for actual production development need. Very Very thank you. I will share your channel as much as possible to everyone. I really like your teaching style and I aslo need that type of javascript teacher. God bless you.
----- SUMMARY ----- Video 12 - Number and Maths in Javascript const score = 400 // JS auto detects it as a number const balance = new Number(100) // Using Number Function to explicitly define number in JS console.log(score) // 400 console.log(balance) // [Number: 100] Note: Number has comparatively less prototype properties (methods) than String Methods with examples: 1. balance.toString() // This converts a number into string 2. balance.toString().length // Once we convert it to String, all properties / methods of Strings are now open to us, such as length 3. balance.toFixed(2) // Used to reduce or round of to specific decimal values - Use Cases a. After calculation of GST b. In Ecommerce website 4. const otherNumber = 23.8966 otherNumber.toPrecision(3) // Output - 23.9 otherNumber = 123.8966 otherNumber.toPrecision(3) // Output - 124 otherNumber = 1123.8966 otherNumber.toPrecision(3) // Output - 1.12e+3 (exponential value) 5. const hundreds = 1000000 hundreds.toLocalString() // By default it converts into US standards hundreds.toLocalString('en-IN') // As per Indian Standards (Note: Check other formats in MDN Docs) 6. Other methods .MAX_VALUE .MIN_VALUE .MAX_SAFE_INTEGER .MIN_SAFE_INTEGER ----- Maths in JS ---- Maths library comes along with JS Methods ---- 1. Math.abs() // Converts +ve / -ve integer values to positive 2. Math.round(4.3) // Output - 4 3. Math.round(4.6) // Output - 5 4. Math.ceil(4.2) // Output - 5 (gives top value) 5. Math.floor(4.9) // Output - 4 (gives bottom value) 6. Math.min(4,3,6,8) // Output - 3 7. Math.max(4,3,6,8) // Output - 8 8. Math.random() // Gives random value between 0 & 1 in decimals Math.random() tricks ----- Math.random()*10 Math.random()*10 + 1 // This assures that values are atleast 1 & more than 1 (Math.random()*10) + 1 // To avoid any BODMAS rule miscalculation ---- Trick to randomize value between range ---- const min = 10 const max = 20 const randomValue = Math.floor((Math.random() * (max - min + 1)) + min)
I just started this course so far It have helped me a lot looking forward to know more about js. Bhaiya one humble request to make a complete video on how to approach companies .
Formula for generating random number : Math.floor(Math.random() * (total no. in the range)) + min_number For example : if you want to generate random number between 1 to 6, then min no. is 1, max no. is 6, total no. in the range is 6 ( max - min + 1), now putting to formula : Math.floor(Math.random() * (6)) + 1 this could be used for ludo dice
I was really having a bad day, but what make me calm and relax these days are watching your videos, thank you so much for everything sir you are an inspiration
At 22:26 if min =10 and max=20 then the value (Math.floor(Math.random()*(max-min +1)) ) => ensure that it will give value in the range [0,10] ..You have said 1 is added to avoid 0 but basically 1 is added to increase the range upto (10) ..if we will not add 1 it will give value in the range [0,9] .. Please clarify it ..And thanks for providing such valuable content.. Love You bhaiyya great series❤️!
Hey, bro in MDN docs it is clearly mentioned Math.random() returns that number that's greater than or equal to 0 and less than 1. So either you include 20 by adding 1 or exclude it by not adding 1, my suggestion is don't add 1, just go with the tradition i.e. docs. *And if you want to include 20 you have to add 1 inside(max- min + 1) not ((max-min) + 1), if you do this you'll get where we started where the value 10 will be excluded i.e. bodmass magic. *But in the video, there is a small explanation mistake at 20:08 where he @chaiaurcode says to avoid 0 you have to add 1 there i.e.(max- min + 1), if you do this only this step you'll get 0 value at some point there is a slimmest of chances because when Math.random() = 0, you will always get 0 because when you multiply anything with 0 obviously you'll get 0. So there's no point in adding "1" here because you'll get 0 at some point. Instead, he'd have added + 1 in the last equation. *Because when you look at the last equation it is correct in terms of the question where we want to include 10 and 20 as well. eg. (0.91*11) +10 = 20.01 or (0*11) +10 = 10😎😎. Hope that I've made my point. At last, JavaScript is a forgiving language so forgive it 😬😬and move on.... You can refer to the same here developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
@@rajrajeshwarsingh3119 The formula is correct. If you want to check, type the values: min1 = 10 max1 = 20 console.log(Math.floor(0.99999 * (max1-min1 + 1)) + min1); console.log(Math.floor(0.00000 * (max1-min1 + 1)) + min1); You can see, the formula is giving correct results for boundary cases and if boundary cases are correct, it means rest of the values will also be fine.
A granular detail that someone may miss while watching the video. Math.random() returns values 0 to 1 where 0 is inclusive but 1 is excluded. Overall, mind blowing series thus far. I'm binge watching :)
Hi dear Hitesh Sir, I liked your way of teaching, because you are not taking long time to explain any topic. I watched and visit other youTube channel instructor who have 1M, 2M, 5M. but they all are taking so long time to give less knowledge and understanding to us. I don't want to publish these name but they are copying you in this paid cources, and session. it's my bad, I came here after mess around/ wasting my time and energy there. And literally your video quality and editing,animation, voice quality it's superb. I am requesting for DSA from you. please provide us. best DSA series. i will be wait for the same. and thank you for providing such a nice content in free of cost. you are great person and my ideal person also.
"🌟 Great content, Chai aur Code! Your videos are both informative and engaging. I've been learning a lot from your tutorials, and the way you explain complex concepts makes coding more accessible. Keep up the fantastic work! 👏💻 #LearningFromTheBest #ChaiaurCode"
Hum isse formula ko use karke ek simple otp generator bana skte jisse understanding or clear hogi Hum bas agr range ko jo min or max likthe hai usse agr hum me min = 100000 and max me max = 999999 krde to hume 6 digt OTP ka range mil jata hai. Principle ekdam same hai bas range ko increase kar do. Example: function Otp() { let min = 100000 let max = 999999 console.log(Math.floor(Math.random() * (max - min + 1) + min)); } Otp(); Try kar ke dekho or ache se samjh ajyga Math.random with range ka case.
Thanks for this wonderful contain 😊 and the way u teach is really appropriate Last line code was little complex but that you you give a good example Although I think I can use Math.ceil isnted of Math.floor But I do understand why did u used this example 😊
Hello sir...main sochra tha ki agar aap Javascript ke concepts padhaye with live implementation of each in the realtime projects. Sir, this will really help the students as they will be knowing what will be the purpose of each topic.
At time 5:23 when the balance is converted to string using the to string() function , is it the copy of balance that is converted or the original variable?I'm asking in reference to the stack heap vedio previously watched of this playlist.
In case someone has doubt in generating the random number between min and max value. //Getting a random integer between two values console.log(Math.floor(Math.random() * (max-min)) + min)// The maximum is exclusive and the minimum is inclusive console.log(Math.floor(Math.random() * (max - min + 1)) + min)// The maximum is inclusive and the minimum is inclusive
A simple explanation that I always think about is "Math.random() sirf 0 se 1 tk random number generate krta hai 0 is inclusive, 1 is exclusive....So in this statement Math.random() * 10, the result can never be equal to 10 qki 10 lane k lie usko 1 se mulitply hona pdega jo ki possible nahi hai, to result hmesha 10 se niche hoga (it could be 9.999999) but 10 nhi hoga, or iske upr se agar aap Math.floor(Math.random() * 10) krte ho to result 0 se 9 tk koi bhi integer ho skta hai but 10 nahi, to 10 ko bhi range me include krne k lie hum usme 1 add kr dete hai.....that is if you do Math.floor(Math.random() * 11) to result [0,10] tk aaega both inclusive.....and at last isme bas aap 1 add kr doge to result [1,10] m convert ho jaega....
similarly, is concept ko max min m bhi leke jaa skte hai
vahi to aur isne to dhang se samjhaya hi nhi aur fake smile karta rehta bus
22:29 actually here , the plus one is added to include the maximum number(20) into the range .. Zero case is already handled by adding +min after it ... For example let's say the random returns 0.99999 then multiply it with 11(20-10+1).. , we will get 10.989.... take the floor value of this which will be 10 and now add it with min value which is 10 so overall answer would be 20(the ending range). That's the maximum case..
Similarly if random returns 0.0122... then everything will get 0 in the left and then adding min(10) to 0 will give us 10 which is the starting range..
Thanks bro. I was confused at first
still not getting
Bravo
best man
best channel
best language
best way of explanation on internet
you are legend in explanation world
Thank you for illuminating our learning journey, one JavaScript tutorial at a time. You're not just a teacher; you're an inspiration
i have already watched ur old javascript series bt this one is awesome
Amazing video, Thank you sir
When we participate in the growth of others, we often end up growing ourselves first. You have done a lot for coders and continue to do so, which is great. I am eager to watch the complete Python course that is currently ongoing. However, I am very busy working on my clients' projects. In my remaining time, I am learning more about JavaScript to improve my knowledge. Although I already know JavaScript, learning from you is both fun and fortunate for me.
Thanks for all you are doing !
you are truly a indian inspiration mentor . thank you for serving india and across the world through your talent
Awesome Sir Thank you👍
Amidst these tough days of my life ,your videos are keeping me calm and sane....your voice is really soothing and the way you explain is impeccable
Formula for generating random number : Math.floor(Math.random() * (total no. in the range)) + min_number
For example : if you want to generate random number between 0 to 10, then min no. is 0, max no. is 10, total no. in the range is 11 ( max - min + 1), now putting to formula :
Math.floor(Math.random() * (11)) + 0
I find this tutorials are so relaxing. 😀 Great playlist.
sir your ability to convey intricate JavaScript concepts in a way that's both approachable and engaging is truly commendable, making us true asset to the learning community."
Nice explanation of Math.random . i really like it
You are the best Teacher i have ever had
Nice video concept clear about numbers and math thanks
literally you're savour i singed up for ibm Frontend development on crousera although that's expensive and paid course but cloud not understand anything and came back to this series
Thank You for explaining very clearly and precisely
"Excellent overview of number & math concepts in JavaScript! Clear explanations and examples. #js"
best Series ALL OVER UNIVERSE, thank you Sir 🙏
Thanks sir! Keep providing such videos!!
This is Pure Gem!
Thank you for making such a beautiful javascript tutorial. Because You teach the actual javascript which is necessary for actual production development need. Very Very thank you. I will share your channel as much as possible to everyone. I really like your teaching style and I aslo need that type of javascript teacher. God bless you.
The way are you teaching ❤️✨✨,i never seen ever my life... Thanks for this series sir
The best thing I'm seeing in whole week.
----- SUMMARY -----
Video 12 - Number and Maths in Javascript
const score = 400 // JS auto detects it as a number
const balance = new Number(100) // Using Number Function to explicitly define number in JS
console.log(score) // 400
console.log(balance) // [Number: 100]
Note: Number has comparatively less prototype properties (methods) than String
Methods with examples:
1. balance.toString() // This converts a number into string
2. balance.toString().length // Once we convert it to String, all properties / methods of Strings are now open to us, such as length
3. balance.toFixed(2) // Used to reduce or round of to specific decimal values
- Use Cases
a. After calculation of GST
b. In Ecommerce website
4. const otherNumber = 23.8966
otherNumber.toPrecision(3) // Output - 23.9
otherNumber = 123.8966
otherNumber.toPrecision(3) // Output - 124
otherNumber = 1123.8966
otherNumber.toPrecision(3) // Output - 1.12e+3 (exponential value)
5. const hundreds = 1000000
hundreds.toLocalString() // By default it converts into US standards
hundreds.toLocalString('en-IN') // As per Indian Standards
(Note: Check other formats in MDN Docs)
6. Other methods
.MAX_VALUE
.MIN_VALUE
.MAX_SAFE_INTEGER
.MIN_SAFE_INTEGER
----- Maths in JS ----
Maths library comes along with JS
Methods ----
1. Math.abs() // Converts +ve / -ve integer values to positive
2. Math.round(4.3) // Output - 4
3. Math.round(4.6) // Output - 5
4. Math.ceil(4.2) // Output - 5 (gives top value)
5. Math.floor(4.9) // Output - 4 (gives bottom value)
6. Math.min(4,3,6,8) // Output - 3
7. Math.max(4,3,6,8) // Output - 8
8. Math.random() // Gives random value between 0 & 1 in decimals
Math.random() tricks -----
Math.random()*10
Math.random()*10 + 1 // This assures that values are atleast 1 & more than 1
(Math.random()*10) + 1 // To avoid any BODMAS rule miscalculation
---- Trick to randomize value between range ----
const min = 10
const max = 20
const randomValue = Math.floor((Math.random() * (max - min + 1)) + min)
G sir my nay pichla assesment kiya string kay methods ka bahut kuch sikhnay ku mila thank you
As usual enjoying this extra ordinary explanation of topics..
Awesome video of Math object
Sir, aise hi aap pls roz video dala kijiye, phir padhne mein bhi maza aayega...... Thanks a lot for your top notch hindi tutorials
I just started this course so far It have helped me a lot looking forward to know more about js. Bhaiya one humble request to make a complete video on how to approach companies .
keep providing us such an amazing lectures
May you live long life
love from Pakistan
Great Man (Salute to you for providing such an amazing content for us ) Thanks
Btw following you from Pakistan 😍😍😍
Explanation is to the point 🔥
toPrecision and Math.random() part was great
Formula for generating random number : Math.floor(Math.random() * (total no. in the range)) + min_number
For example : if you want to generate random number between 1 to 6, then min no. is 1, max no. is 6, total no. in the range is 6 ( max - min + 1), now putting to formula :
Math.floor(Math.random() * (6)) + 1
this could be used for ludo dice
sir your javascript series just became a game changer of my programming experience❤
OutStanding Explaination💖💖💖
Amazing teaching skill brother, keep up the good work. Also please make a video on how to get a job with basic HTML, CSS & JS while we keep learning.
thanks for sharing quality content
kia baat ha sir ap ke 😍
u made javascript easy for me
I was really having a bad day, but what make me calm and relax these days are watching your videos, thank you so much for everything sir you are an inspiration
continuining day 3. Amazinng content sir ji.
thank you your videos make easy js for me
sir aapki sari video bhot helpful hain, thank you. sir vo sach me chai tha kya😄😄
Really like the playlist.
Sir You Are Just Awesome
well explained ...... thank you so much
sir ap ki padani ka alg style pura cosept clear ho jata h
At 22:26 if min =10 and max=20 then the value (Math.floor(Math.random()*(max-min +1)) ) => ensure that it will give value in the range [0,10] ..You have said 1 is added to avoid 0 but basically 1 is added to increase the range upto (10) ..if we will not add 1 it will give value in the range [0,9] .. Please clarify it ..And thanks for providing such valuable content.. Love You bhaiyya great series❤️!
you are absolutely right, basically one is added to set the uppper limit to max value.
Hey, bro in MDN docs it is clearly mentioned Math.random() returns that number that's greater than or equal to 0 and less than 1. So either you include 20 by adding 1 or exclude it by not adding 1, my suggestion is don't add 1, just go with the tradition i.e. docs.
*And if you want to include 20 you have to add 1 inside(max- min + 1) not ((max-min) + 1), if you do this you'll get where we started where the value 10 will be excluded i.e. bodmass magic.
*But in the video, there is a small explanation mistake at 20:08 where he @chaiaurcode says to avoid 0 you have to add 1 there i.e.(max- min + 1), if you do this only this step you'll get 0 value at some point there is a slimmest of chances because when Math.random() = 0, you will always get 0 because when you multiply anything with 0 obviously you'll get 0. So there's no point in adding "1" here because you'll get 0 at some point. Instead, he'd have added + 1 in the last equation.
*Because when you look at the last equation it is correct in terms of the question where we want to include 10 and 20 as well. eg. (0.91*11) +10 = 20.01 or (0*11) +10 = 10😎😎. Hope that I've made my point. At last, JavaScript is a forgiving language so forgive it 😬😬and move on....
You can refer to the same here developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
@@rajrajeshwarsingh3119 The formula is correct. If you want to check, type the values:
min1 = 10
max1 = 20
console.log(Math.floor(0.99999 * (max1-min1 + 1)) + min1);
console.log(Math.floor(0.00000 * (max1-min1 + 1)) + min1);
You can see, the formula is giving correct results for boundary cases and if boundary cases are correct, it means rest of the values will also be fine.
Thanks Hitesh it's really helpful to revise the basics ❤❤
The things you are charity in free, can't be got in paid too. thanks a lot sir.
"Excellent tutorial! Clear explanations of number and math concepts in JavaScript using Chai. Highly recommended."
maine pehle padha hua tha JavaScript but ye sab nahi pata tha Thank You sir for this amazing course!!
the formula was very intresting and this class was very memorebel
great effort
Great explanation
Thank you so much sir 😊
You are great
Thank you for this series
excellent...
Are garda hai ye wala video, har baar ki tarah ji😀
Excellent,useful content Bhai..
Thanks for this amazing tutorial sir!
amazing keep it up
A granular detail that someone may miss while watching the video. Math.random() returns values 0 to 1 where 0 is inclusive but 1 is excluded.
Overall, mind blowing series thus far. I'm binge watching :)
Hi dear Hitesh Sir, I liked your way of teaching, because you are not taking long time to explain any topic. I watched and visit other youTube channel instructor who have 1M, 2M, 5M. but they all are taking so long time to give less knowledge and understanding to us. I don't want to publish these name but they are copying you in this paid cources, and session. it's my bad, I came here after mess around/ wasting my time and energy there. And literally your video quality and editing,animation, voice quality it's superb. I am requesting for DSA from you. please provide us. best DSA series. i will be wait for the same. and thank you for providing such a nice content in free of cost. you are great person and my ideal person also.
"🌟 Great content, Chai aur Code! Your videos are both informative and engaging. I've been learning a lot from your tutorials, and the way you explain complex concepts makes coding more accessible. Keep up the fantastic work! 👏💻 #LearningFromTheBest #ChaiaurCode"
this video is really helpfull.
content level 😍👌
thanks bro learnt new things
1 no. sir ji💯💯
Thanks Sir
awesome
Best series ❤
Great
Good one
console.log((Math.random()*(max-min))+min); it will also work.
Super❤
frist if all thankyou so much sir, and i think our jen-z are very lucky bicos of we have such kind of teachers.
Thank you
❣🥰🥰
maja aa gya chicha jaan
We would really appreciate a series on DSA with JS.
good sir
Shukriya,
Gazab :)
Nice Explanation!!
gud one
Hum isse formula ko use karke ek simple otp generator bana skte jisse understanding or clear hogi
Hum bas agr range ko jo min or max likthe hai usse agr hum me min = 100000 and max me max = 999999 krde to hume 6 digt OTP ka range mil jata hai. Principle ekdam same hai bas range ko increase kar do.
Example:
function Otp() {
let min = 100000
let max = 999999
console.log(Math.floor(Math.random() * (max - min + 1) + min));
}
Otp();
Try kar ke dekho or ache se samjh ajyga Math.random with range ka case.
amazing video sir!!
This man is ❤❤❤
Quality content ❤
Thanks for this wonderful contain 😊 and the way u teach is really appropriate
Last line code was little complex but that you you give a good example
Although I think I can use Math.ceil isnted of Math.floor
But I do understand why did u used this example 😊
cool
Hello sir...main sochra tha ki agar aap Javascript ke concepts padhaye with live implementation of each in the realtime projects. Sir, this will really help the students as they will be knowing what will be the purpose of each topic.
my every daut was clear and now iam good in numbers and math
I like video ❤❤❤❤❤❤
Dhanyawad guruji 🙏
At time 5:23 when the balance is converted to string using the to string() function , is it the copy of balance that is converted or the original variable?I'm asking in reference to the stack heap vedio previously watched of this playlist.
Sir chai aur code is best
In case someone has doubt in generating the random number between min and max value. //Getting a random integer between two values
console.log(Math.floor(Math.random() * (max-min)) + min)// The maximum is exclusive and the minimum is inclusive
console.log(Math.floor(Math.random() * (max - min + 1)) + min)// The maximum is inclusive and the minimum is inclusive