javascript - Change background color on refresh with Vanilla JS -


There is a problem changing the background color when I refresh each one. Any help is appreciated that this is my JS yet:

  var color = ['# 760c8', '# 4782b1', '# e889c']; Var change background = function () {document.body.style.background = colors ([Math.floor (Math.random (* * colors.length)]);}; Change background ();    

You are almost there. In the line

  document.body.style.background = colors ([Math.floor (Math.random (* * colors.length)];   

You [Math.flur (Math.Rendum (*) * Colors Length ).] Otherwise you think that you want to call colors as a code. The index wants to use an array of what the square brackets do, so it should

  document.body.style.background = colors [Math.floor (Math.random (* * colors.length) ];   

and it will be alright.

Comments

Popular posts from this blog

c# - Roxy file manager in MVC doesn't accept session path -

php - proc_open Too many open files in long running Symfony Console app -

c# - Show a huge number of data in DevExpress GridView -