Generating a random number in javascript
ฝัง
- เผยแพร่เมื่อ 6 ก.ย. 2024
- Welcome to a youtube channel dedicated to programming and coding related tutorials. We talk about tech, write code, discuss about cloud and devops. That’s what we do all day, all year. We roll out a lot of series and videos on our channel.
All the learning resources such as code files, documentations, articles and community discussions are available on our website:
chaicode.com/
You can find our discord link, github link etc on the above website.
Twitter/X link: x.com/hiteshdo...
Discord link: hitesh.ai/discord
Learn React with 10 projects: • Let's learn react from...
Learn Docker: • A practical guide on D...
Learn Kubernetes: • Complete Kubernetes Co...
How does a browser works: • How does a browser wor...
How nodejs works: • How node JS works | En...
Learn Redux-toolkit: • Learn Redux Toolkit in...
Learn NextJS: • Nextjs Full stack course
Learn Typescript: • Why to learn Typescript
Learn Javascript: • Welcome to new JavaScr...
Learn React Native: • React Native Mastery: ...
Learn Zustand: • React state management...
Learn Golang: • How to get started wit...
You are so great teacher. Your work is highly appreciable.
such a
Thank you for the tutorial! Coming from Python, the start/end looks complex VS:
import random
dice = random.randrange(20, 26)
ceil and floor are actually other names for Lowest Integer Function and Greatest Integer Function
Never Seen a Teacher like u✔
let floatRes = Result
can also bring the same output, no neet to write to.Fixed(2) for twice. at 5:12
Hi Hitesh, great to follow your videos.I am learning a lot from these videos.Thanks a lot!!
Here I have written a very simple game.I want to share the code
let userTurn=function(){
let user = Number(prompt('enter a random number'));
return user;
}
let computerTurn=function(){
let system = Math.floor(Math.random()*10);
return system;
}
for(i=1;ib){
console.log('user wins');
}
else{
console.log('computer wins');
}
}
What do you say about the code and how can I make it better.
Thanks in advance.
we should use round() for get its closest integer so why we use floor or ceil
Hitesh, your concept of viewing and doing is too good. Examples you have selected are excellent, easy to understand. Technically to the point. Hope to see more in further videos
You are not a programmer , you are a magician
23 video u ask subscribe , just now i did that. awesome videos .....life time videos
that was quite a good explanation man thank you I have been looking so much but couldn't find any except yours. thanks again
Thanks man, I was looking for this because I didn't understand how it works but you explain it very well and simple. Greetings from Venezuela.
Thank you.. Now I understand the formula..
it was 1:30 in the morning and you were making videos for us
let upper = 1;
let lower = 10;
if (upper > lower) {
let randomizer = function(up, low) {
let myRandom = Math.random() * (up - low);
let final = myRandom + 20;
return `the random value inclusive of ${upper} and ${lower} is ${Math.round(
final
)}`;
};
console.log(randomizer(upper, lower));
} else if (upper === lower) {
console.log("Upper Lower can't be same");
} else {
console.log("Upper value cannot be smaller than Lower");
}
Thanks, bro I used Math.round to include both upper limit and lower limit.
This is really cool one!
And you''re the great mentor for us!
you're a
such an interesting video, looking for it quite long time . lotsOfLove keep rocking Hitesh , 'm on my mac cant put smiles here please take all my wishes
Thanks for putting the tutorial together. :)
Is there a way to Password Protect online videos (TH-cam, Vimeo... etc) with some if not all of these features?
Random Password
Set the Expiration time or date
Set the Total time a video can be viewed
Set how many times the password is allowed
Setup Password Groups
I know it's asking a lot, if you're busy, I understand. You seem to have the skills to make it happen. Just putting it out there.
Instead of Math.Floor, if we provide '0' value to the toFixed it still shows integer value without any decimal places then what's the point of using the Math.floor?
Please explain...
Wow I really enjoii this series
Loving this series alot
Hoping to have a complete bunch of JS series
And sir please give alot of projects along with them
Thanks you sir , I clearly understand How it work
Your dedication really inspires..!👌👍🏼
Thanks sir for this video 😊
Finally my confusion was clear
Always nice stuffs from you. And I want to know if you can share your system configuration pls
Thanks bro.. i liked the way you explain the details. Subscribed!!
It's really an awesome tutorials for beginners. I am going to subscribe it.
i can;'t wrap my head around the fact that i would have never been able to write this function from the top of my head
yeah well, im back! and this looks way too easy. Ive used the math.random function in more complicated functions such as color and string generators. Don't give up!
love your teaching keep uploading videous like even if u dont get many views later on but many really watch all of it
let message = "I love the tutorial";
if(message)
{
console.log(message);
}
thank you sir. I am enjoying your tutorial.
Thanks
bhai there is no need if if else statement and u not use properly that if else statement stuff
@@dikshitkaushik8387 nothing wrong with the code bro. He has checked whether the message is exist? if its true return message. He has done a wonderful job
sir how we can genreate random number in a given range without using math.Random() in javascript
And this series is really awesome
sir, i like this video as compare to random password generator project.
22/7 is not Pi, it’s just close to Pi. Pi is an infinitely long string of numbers, and is therefore impossible to write as a fraction.
how to stop generating the same random numbers with the database I want to generate roll numbers which should not be same so tell me.
this is beyond perfect.
thanks a ton.
I NEED PANCARD VALIDATION THROUGH THE TEXTBOX THAT 5TH CHARACTER IN PANCARD NUMBER MUST MATCHES WITH THE SURNAME
Thanks I understand The concept now
sir , wud u please tell us tht how to make dynamic img slider using JS ??????
But sir I have also got 0 .... sir what is the reason... please reply
I think you are a developer...may be you know which are the mostly used all functions in Math lib . May be this will be useful. Because there are many in the documentation.
Thanks
Result = 22/7
But u have forgot to put let or var before result...
But you got correct answer..How}??
in javascript if you do not declare var or let the variable is still accessible and it becomes a global variable
@@michaelobeng7660 yes you are true
watch his viedoe of var and let he is telling local and global
"THE" best :)
Thanku
thank you
concept clear thanks
Can u create website for me i want to hire u as developer?
wao,, Another great video.
please also give series lyk this for node n react js too
Available here
courses.learncodeonline.in
Smallest Code
let a = Math.ceil(Math.random()*6);
console.log(a);
Thank you you are great !
Thank you so much sir......
*Just because you started this series your subscribers got increased a lot
I think You should put some more free series on react native & database connectivity with same as well it will increase subscribers in Huge nos*
Check again. Views on regular videos is high and views on JS series is so low. Anyways, these numbers are just numbers. I am just looking to move forward.
I dont know why did you take this long route, i think you could have simply showed us :
let dice = Math.floor(Math.random()*6)+1
and its done.
maybe he is trying to teach upper and lower concept.
btw I got output by using Math.floor(Math.random()*6)+1 thanku
Hello sir can you please explain me this code
//generate random numbers between 83 to 93
let upper = 93;
let lower = 83;
let randomNum = Math.ceil(Math.random() *(upper - lower)) + lower;
console.log(randomNum);
93 - 83 = 10 . so you random a number from 0 to 10. and the end "+lower" means 83. , which means you random a number from 83 to 83 +10 which is 93, and result is 83 to 93
You have used ceil so range will be from 1 to 10, + lower will make the range 84 to 93
math.random() * 5+1 doesn't gave 0 value how to deal with that
9:52 starts talking about random
Nice sir:)
thanks sir
why can't we just use math.ceil on math.random()*6
can you please elabore by which i can try
Figura del partido
yes sir
Why don't we need to import math first?
Well random in python is easy than js
who is here in 2020-corona panademic ?
Thanks Hitesh for being awesome. I just created a function for random and let me know what you think?
jsbin.com/comuruh/edit?js,console
That was not tricky at all sir. Catched in the very first exercise.
I think you are working in google
2:35 :DDDDDD
do you love maths? cuz i hate it
😂😂
thank you