Advertisement
Guest User

js color game

a guest
Jan 17th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2.         var acolors = ["crimson", "aqua", "lawngreen", "coral", "darkblue", "violet", "grey", "yellow", "blueviolet"];
  3.  
  4.         document.getElementById("output").style.backgroundColor="crimson";
  5.  
  6.         function color() {
  7.             acolors = shuffle(acolors);
  8.  
  9.             for (var i=0; i<acolors.length; i++) {
  10.                 var id = "td"+(i+1);
  11.                 var kleur = acolors[i];
  12.                 document.getElementById(id).style.backgroundColor= kleur
  13.             }
  14.         document.getElementById("output").style.backgroundColor="crimson";
  15.         }
  16.         function shuffle(arr) {
  17.             for (var j, x, i = arr.length; i; j = Math.floor(Math.random() *i ), x = arr[--i], arr[i] = arr[j], arr[j] = x);
  18.             return arr;
  19.         }
  20.         function setTimer() {
  21.             setInterval(color, 2000);
  22.         }
  23.     </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement