Math的數(shù)學(xué)對象

console.log(Math.floor(25.6));//下取整25。

console.log(Math.ceil(25.4));//上取整26。

console.log(Math.random( ));//輸出0-1之間的隨機(jī)小數(shù)。

求隨機(jī)數(shù)max,min之間的隨機(jī)數(shù):

console.log(Math.floor(math.random()*(min-max+1)+max));

練習(xí):隨機(jī)變換顏色

setInterval(function(){

var div = document.querySelector('.box');

var r = Math.floor(Math.random() * (255));

var g = Math.floor(Math.random() * (255));

var b = Math.floor(Math.random() * (255));

div.style = 'background:rgb(' + r + ',' + g + ',' + b + ')';

console.log(r);

console.log(g);

console.log(b);

},100);

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • "use strict";function _classCallCheck(e,t){if(!(e instanc...
    久些閱讀 2,132評論 0 2
  • console.log(Math.floor(25.6));//下取整25。 console.log(Math.c...
    常婧帥閱讀 450評論 0 0
  • .寫一個(gè)函數(shù),返回從min到max之間的 隨機(jī)整數(shù),包括min不包括max function randomness...
    邢烽朔閱讀 364評論 0 1
  • 小周未父母加班的小伙伴可以過來聯(lián)盟 一只羊是放,一群羊是玩! 夏日清涼價(jià) ,大小一餐25/元
    Q同學(xué)會閱讀 231評論 0 0
  • 決定做簡書碼字俠也就是這幾天的突發(fā)想法,總覺得該用一些方式來記錄自己的點(diǎn)滴人生。畢竟書讀的少,記性也沒多好,在想要...
    咕嘟小仙閱讀 289評論 0 2

友情鏈接更多精彩內(nèi)容