Calling a function every 60 seconds

后端 未结 13 2059
情书的邮戳
情书的邮戳 2020-11-22 08:24

Using setTimeout() it is possible to launch a function at a specified time:

setTimeout(function, 60000);

But what if I would l

13条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 09:21

    function random(number) {
      return Math.floor(Math.random() * (number+1));
    }
    setInterval(() => {
        const rndCol = 'rgb(' + random(255) + ',' + random(255) + ',' + random(255) + ')';//rgb value (0-255,0-255,0-255)
        document.body.style.backgroundColor = rndCol;   
    }, 1000);
    
    it changes background color in every 1 second (written as 1000 in JS)

提交回复
热议问题