Explain Math.floor(Math.random())

前端 未结 6 1202
轻奢々
轻奢々 2020-12-19 07:52

I have seen many places using Math.floor() and Math.random()

like below

$(\'a.random-color\').hover(function() { //mouseove         


        
6条回答
  •  被撕碎了的回忆
    2020-12-19 08:13

    Math.floor will give a whole number and gets rid of the decimals.

    Math.random returns a number between 0 and 1 and therefore will produce decimal numbers when multiplied with 256. Thats why you want to use floor to get rid of the decimals otherwise the rgb values won't work.

提交回复
热议问题