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

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -