Guest User

Untitled

a guest
Jul 20th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. // Restart Game Button
  2. var restart = document.querySelector('#b');
  3.  
  4. // Grab all the squares
  5. var squares = document.querySelectorAll("td");
  6.  
  7. var grid = document.querySelector("tr")
  8.  
  9. var x = document.getElementById("change").innerHTML;
  10.  
  11. // Clear Squares Function
  12. function clearBoard() {
  13. for (var i = 0; i < squares.length; i++) {
  14. squares[i].textContent = '';
  15. }
  16.  
  17. }
  18. restart.addEventListener('click',clearBoard)
  19.  
  20.  
  21. // Create a function that will check the square marker
  22.  
  23.  
  24. var header = document.querySelector("h1")
  25. var tablecolor = document.querySelector("td")
  26. // Then you can interface with the object.
  27.  
  28. // Interface with the style.
  29. //You will see a ton of options show up!
  30. //header.style.color = 'blue'
  31. //tablecolor.style.color = 'blue'
  32. //grid.style.color = 'red'
  33. // Now let's connect it to the script to
  34. // change it once every second to a random color!
  35.  
  36. // Random Color Function:
  37.  
  38. // http://stackoverflow.com/questions/1484506/random-color-generator-in-javascript
  39.  
  40. function getRandomColor(){
  41. var letters = "0123456789ABCDEF";
  42. var color = '#';
  43. for (var i = 0; i < 6; i++) {
  44. color += letters[Math.floor(Math.random()*16)];
  45. }
  46. return color
  47. }
  48. function changeMarker(){
  49. if(this.textContent === ''){
  50. this.textContent = 'X';
  51. // console.log(marker)
  52. }else if (this.textContent === 'X') {
  53. this.textContent = 'O';
  54. }else {
  55. this.textContent = '';
  56. }
  57. };
  58. // Simple function for clarity
  59. function changeHeaderColor(){
  60. colorInput = getRandomColor()
  61. header.style.color = colorInput;
  62. }
  63.  
  64. function changeBorderColor() {
  65. var table = document.getElementById("table_row").getElementsByTagName("td");
  66. for(var i=0; i<table.length; i++) {
  67. var td = table[i];
  68. td.style.borderColor = getRandomColor();
  69. }
  70. }
  71. // Use a for loop to add Event listeners to all the squares
  72. for (var i = 0; i < squares.length; i++) {
  73. squares[i].addEventListener('click', changeMarker);
  74. squares[i].style.color = getRandomColor()
  75. }
  76.  
  77. function changeXColor(){
  78. colorInput = getRandomColor();
  79. x.style.color = colorInput;
  80. }
  81.  
  82. setInterval("changeHeaderColor()",300);
  83. setInterval("changeBorderColor()",305);
  84. setInterval("changeXColor()",300);
Add Comment
Please, Sign In to add comment