Inbuilt function

what is the use of Math.floor and what does math.floor(math.random()) does please explain me any one

floor floors the number (rounds down), so math.floor(math.random()) will floor a random number

1 Like

math.random has 0 to 1 why should it be rounded

true, but this is introduced in steps so next time we can generate a random number one of the following random numbers: 0, 1, 2, 3 or 4 with the following code:

math.floor(math.random() * 5)
1 Like

thank u i understood now

can you give me a demo example of Math.floor(math.random())
like math.floor() first then math.floor(math.ramdom()) plz

why does demo example mean?

You can just experiment with code within the lessons (or outside the lessons like on jsbin), to study code further

furthermore, you can check external docs, MDN always has good docs:

1 Like

i’m sorry but how would math.floor(math.rando()*5) can give 2,3,4,5
math.random() varies from 0-1 floor(0.33) gives 0 right how can we get 2,3,4,5

math.random()*5 happens first, so lets say math.random generates 0.7 we get 0.7 * 5 which is 3.5, which will floor to 3

1 Like

oh thank you i got it pretty clear this time
can you suggest what is a demanded programming language now a days and coming 4 yrs probably

plenty, JS with html and css (front-end), JS for back-end even, python, Java and more

stackoverflow always has surveys:

in includes job tasks, language and basicly everything you need to know

1 Like