Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var box0 = document.getElementById("box0");
  2. var box1 = document.getElementById("box1");
  3. var box2 = document.getElementById("box2");
  4. var box3 = document.getElementById("box3");
  5.  
  6.  
  7. var color1 = "rgb(" + (Math.floor(Math.random() * 256)) + "," + (Math.floor(Math.random() * 256)) + "," + (Math.floor(Math.random() * 256)) + ")";
  8. var color2 = "rgb(" + (Math.floor(Math.random() * 256)) + "," + (Math.floor(Math.random() * 256)) + "," + (Math.floor(Math.random() * 256)) + ")";
  9. var color3 = "rgb(" + (Math.floor(Math.random() * 256)) + "," + (Math.floor(Math.random() * 256)) + "," + (Math.floor(Math.random() * 256)) + ")";
  10.  
  11. var color0 = [color1, color2, color3];
  12.  
  13. var randomNumber = color0 [Math.floor(Math.random() * 3)];
  14.  
  15.  
  16. box0.style.backgroundColor = randomNumber;
  17. box0.style.width = "100px";
  18. box0.style.height = "100px";
  19. box0.style.display = "inline-block";
  20.  
  21.  
  22. box1.style.backgroundColor = color1;
  23. box1.style.width = "100px";
  24. box1.style.height = "100px";
  25. box1.style.display = "inline-block";
  26.  
  27. box2.style.backgroundColor = color2;
  28. box2.style.width = "100px";
  29. box2.style.height = "100px";
  30. box2.style.display = "inline-block";
  31.  
  32. box3.style.backgroundColor = color3;
  33. box3.style.width = "100px";
  34. box3.style.height = "100px";
  35. box3.style.display = "inline-block";
  36.  
  37.  
  38. //var newcolor = [color1, color2, color3];
  39.  
  40. //var new0 = newcolor [Math.floor(Math.random() * 3)];
  41. //var new1 = newcolor [Math.floor(Math.random() * 3)];
  42. //var new2 = newcolor [Math.floor(Math.random() * 3)];
  43. //var new3 = newcolor [Math.floor(Math.random() * 3)];
  44.  
  45.  
  46. box1.onclick = function click () {
  47.     if( box1.style.backgroundColor === box0.style.backgroundColor){
  48.         resultatSvar.innerHTML = "Riktig!";
  49.         box1.style.width = "105px";
  50.         box1.style.height = "105px";
  51.         box1.style.border = "solid 2px";
  52.        //box1.style.backgroundColor = new1;
  53.         //box0.style.backgroundColor = new0;
  54.        
  55.     }else{
  56.        
  57.         resultatSvar.innerHTML = "Feil!";
  58.     }
  59.  
  60. }
  61.  
  62. box2.onclick = function click () {
  63.     if( box2.style.backgroundColor === box0.style.backgroundColor){
  64.         resultatSvar.innerHTML = "Riktig!";
  65.         box2.style.width = "105px";
  66.         box2.style.height = "105px";
  67.         box2.style.border = "solid 2px";
  68.         //box2.style.backgroundColor = new2;
  69.         //box0.style.backgroundColor = new0;
  70.     }else{
  71.        
  72.         resultatSvar.innerHTML = "Feil!";
  73.     }
  74.  
  75. }
  76.  
  77. box3.onclick = function click () {
  78.     if( box3.style.backgroundColor === box0.style.backgroundColor){
  79.         resultatSvar.innerHTML = "Riktig!";
  80.         box3.style.width = "105px";
  81.         box3.style.height = "105px";
  82.         box3.style.border = "solid 2px";
  83.        //box3.style.backgroundColor = new3;
  84.         //box0.style.backgroundColor = new0;
  85.     }else{
  86.        
  87.         resultatSvar.innerHTML = "Feil!";
  88.     }
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement