Number and Maths in Javascript | chai aur #javascript

preview_player
Показать описание
Комментарии
Автор

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 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 is if you do Math.floor(Math.random() * 11) to result [0, 10] tk aaega both at last isme bas aap 1 add kr doge to result [1, 11] m convert ho jaega....

similarly, is concept ko max min m bhi leke jaa skte hai

pankajpanday
Автор

best man
best channel
best language
best way of explanation on internet
you are legend in explanation world

tech_channel
Автор

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 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..

monty
Автор

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 =
hundreds.toLocalString() // By default it converts into US standards
// 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)

MahodarMajgaonkar
Автор

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

kushagraagrawal
Автор

Thank you for illuminating our learning journey, one JavaScript tutorial at a time. You're not just a teacher; you're an inspiration

faridullah
Автор

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 !

RahulSharma-wzyv
Автор

At 22:26 if min =10 and max=20 then the value +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❤️!

harshkesharwani
Автор

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."

tech_channel
Автор

"Excellent tutorial! Clear explanations of number and math concepts in JavaScript using Chai. Highly recommended."

babarshabbir
Автор

Thanks for the Video Sir. It's great that we have a great tutor ( Hitesh Sir)❤

sameer
Автор

--> returns a random number between min (included) and max (excluded)
function getRndInteger(min, max) {
return Math.floor(Math.random() * (max - min) ) + min;
}
-->returns a random number between min and max (both included)
function getRndInteger(min, max) {
return Math.floor(Math.random() * (max - min + 1) ) + min;
}

EyeGuy
Автор

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 :)

thecalgarians
Автор

"Excellent overview of number & math concepts in JavaScript! Clear explanations and examples. #js"

babarshabbir
Автор

i have already watched ur old javascript series bt this one is awesome

kanhucharanpradhan
Автор

keep providing us such an amazing lectures
May you live long life
love from Pakistan

tech_channel
Автор

Thank you to Hitesh Sir for making such an awesome video! 🙌🎥 Brushing up on my JS knowledge 🧠

viraljain
Автор

You are the best Teacher i have ever had

yosayaan
Автор

Explanation is to the point 🔥

toPrecision and Math.random() part was great

akashthoriya
Автор

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 = and max me max = 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 =
let max =
* (max - min + 1) + min));
}

Otp();

Try kar ke dekho or ache se samjh ajyga Math.random with range ka case.

sayandipbhattacharya