Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const colors = [
  2.     "red", "green", "blue", "purple",
  3.     "yellow", "pink", "orange", "brown",
  4.     "teal", "aqua", "cyan", "navy",
  5.     "red", "green", "blue", "purple",
  6.     "yellow", "pink", "orange", "brown",
  7.     "teal", "aqua", "cyan", "navy",
  8. ];
  9.  
  10. let fields = document.getElementsByClassName("field");
  11. fields = [...fields];
  12. fields.pop();
  13.  
  14. const coloring = function () {
  15.     for (let i = 0; i <= 23; i++) {
  16.         console.log(i);
  17.         fields[i].style.backgroundColor = colors[Math.floor(Math.random() * colors.length)];
  18.         console.log(colors.splice(i, 1));
  19.     }
  20. }
  21.  
  22. coloring();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement