From b1a46bfde1a59f2106d37065973525e3901fd6d6 Mon Sep 17 00:00:00 2001 From: brookecowey Date: Wed, 8 Feb 2023 19:09:16 -0600 Subject: [PATCH 1/4] pushing up --- index.html | 17 ++++++++++++++--- scripts.js | 4 +++- tictactoe.css | 4 ++-- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index 19d0dee..649b254 100644 --- a/index.html +++ b/index.html @@ -20,10 +20,21 @@

Welcome to Tic Tac Toe

- - + + + + + + + + + + + + + + - diff --git a/scripts.js b/scripts.js index ba09e74..8142f10 100644 --- a/scripts.js +++ b/scripts.js @@ -21,7 +21,9 @@ const handleClick = (element) => { // this next line prevents an X being changed to an O or an O being changed to an X by... // checking to see if the square clicked has anything in it, if not continue + console.log (document.getElementById(element.id).innerHTML', document.getElementById(element.id).innerHTML) if(!document.getElementById(element.id).innerHTML){ + addMarker(element.id) } } @@ -44,7 +46,7 @@ const addMarker = (id) => { console.log(`Therefore, a "${currentMarker}" should be placed in the square with the id: ${id}`) // @TODO-2: Build a line of code that will set the innerHTML property of the element that was clicked to the "currentMarker" - + document.getElementById (id).innerHTML=currentMarker // @TODO-2.5: MIX & MATCH, You will need the following pieces of code to build that line: // = currentMarker // .getElementById(id) diff --git a/tictactoe.css b/tictactoe.css index 981de05..41ffa1e 100644 --- a/tictactoe.css +++ b/tictactoe.css @@ -7,10 +7,10 @@ td { height:150px; width:150px; text-align: center; - border: 5px solid black; + border: 5px solid rgb(250, 2, 2); font-size: 100px; } table { margin: auto auto; -} \ No newline at end of file +} From 64da005f310c36b62f7d8210a265be08d1931c86 Mon Sep 17 00:00:00 2001 From: brookecowey Date: Sat, 11 Feb 2023 12:01:35 -0600 Subject: [PATCH 2/4] added javascript --- index.html | 2 +- scripts.js | 97 +++++++++++++++++++----------------------------------- 2 files changed, 35 insertions(+), 64 deletions(-) diff --git a/index.html b/index.html index 649b254..de4d455 100644 --- a/index.html +++ b/index.html @@ -6,7 +6,7 @@ - +
diff --git a/scripts.js b/scripts.js index 8142f10..8420e80 100644 --- a/scripts.js +++ b/scripts.js @@ -4,105 +4,76 @@ // 1. Read the code below one block at a time. // 2. Look for the @TODOs, and figure out how to fix them. - // next to each @TODO you will find tasks that need to be finished +// next to each @TODO you will find tasks that need to be finished // The variable will change from X to O based on what player turn it is. We need to hold this so we can place an X or O on the board when they're clicked. -let currentMarker = 'X' +let currentMarker = "X"; - - - -// this "handleClick" function is called when a box is clicked. Here, "element" will hold the same value as "this" does in the HTML. +// this "handleClick" function is called when a box is clicked. Here, "element" will hold the same value as "this" does in the HTML. // "this" is a special word in JS but "element" could have been "thing" or "el" or whatever we wanted it to be as long as we use it again in the "console.log" statement const handleClick = (element) => { - // this uses the "log" method on the "console" to log out the element's id so we can see it with our human eyes - console.log(`The element you clicked on has an id: ${element.id}`) + console.log(`The element you clicked on has an id: ${element.id}`); // this next line prevents an X being changed to an O or an O being changed to an X by... // checking to see if the square clicked has anything in it, if not continue - console.log (document.getElementById(element.id).innerHTML', document.getElementById(element.id).innerHTML) - if(!document.getElementById(element.id).innerHTML){ - - addMarker(element.id) + console.log( + document.getElementById(element.id).innerHTML, + document.getElementById(element.id).innerHTML + ); + if (!document.getElementById(element.id).innerHTML) { + addMarker(element.id); } -} - - - - - - - - - - +}; // this function places the "currentMarker" inside the HTML element that was clicked and calls the "changeMarker" function. const addMarker = (id) => { + // @TODO-1: Open the console tab in your Chrome Inspector Tool and click on the top-left square to see what's logged to the console. + console.log(`*** The current marker is: ${currentMarker}. ***`); + console.log( + `Therefore, a "${currentMarker}" should be placed in the square with the id: ${id}` + ); - // @TODO-1: Open the console tab in your Chrome Inspector Tool and click on the top-left square to see what's logged to the console. - console.log(`*** The current marker is: ${currentMarker}. ***`) - console.log(`Therefore, a "${currentMarker}" should be placed in the square with the id: ${id}`) - // @TODO-2: Build a line of code that will set the innerHTML property of the element that was clicked to the "currentMarker" - document.getElementById (id).innerHTML=currentMarker + document.getElementById(id).innerHTML = currentMarker; // @TODO-2.5: MIX & MATCH, You will need the following pieces of code to build that line: // = currentMarker // .getElementById(id) // document - // .innerHTML - - changeMarker() -} - - - - - - - - + // .innerHTML + changeMarker(); +}; // This "changeMarker" function changes "X" to "O" in the "currentMarker" variable or "O" to "X" const changeMarker = () => { - if(currentMarker === "X"){ - currentMarker = "O" + if (currentMarker === "X") { + currentMarker = "O"; } else { - currentMarker = "X" + currentMarker = "X"; } -} - - - - - - - - - +}; // This "resetBoard" function is called when the user clicks on the "Restart" button. const resetBoard = () => { - // @TODO-3: To make your "Restart" button work you'll need to build a line of code here that: - // collects all of the "td" elements into an HTML Collection: https://www.w3schools.com/jsref/dom_obj_htmlcollection.asp - + // collects all of the "td" elements into an HTML Collection: https://www.w3schools.com/jsref/dom_obj_htmlcollection.asp + + const squares = document.getElementsByTagName("td"); + // @TODO-3.5: MIX & MATCH, You will need the following pieces of code to build that line: // squares // .getElementsByTagName("TD") // = // document // const - - // loops over the HTML Collection of TDs and clears out the Xs and Os - for (i=0; i < squares.length; i++) { + // loops over the HTML Collection of TDs and clears out the Xs and Os + for (i = 0; i < squares.length; i++) { // will log out the id of each square as it loops over them. - console.log(squares[i].id) + console.log(squares[i].id); // sets the innerHTML to null to replace the "X" or "O" - squares[i].innerHTML = null - } -} \ No newline at end of file + squares[i].innerHTML = null; + } +}; From 1ef7336edc5b77bb17740e3dc0fcda0017eadff2 Mon Sep 17 00:00:00 2001 From: brookecowey Date: Wed, 22 Feb 2023 20:35:58 -0600 Subject: [PATCH 3/4] added --- scripts.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/scripts.js b/scripts.js index 8420e80..26e953c 100644 --- a/scripts.js +++ b/scripts.js @@ -8,6 +8,12 @@ // The variable will change from X to O based on what player turn it is. We need to hold this so we can place an X or O on the board when they're clicked. let currentMarker = "X"; +let board = [ + ["","",""], + ["","",""], + ["","",""] +] + // this "handleClick" function is called when a box is clicked. Here, "element" will hold the same value as "this" does in the HTML. // "this" is a special word in JS but "element" could have been "thing" or "el" or whatever we wanted it to be as long as we use it again in the "console.log" statement @@ -22,7 +28,7 @@ const handleClick = (element) => { document.getElementById(element.id).innerHTML ); if (!document.getElementById(element.id).innerHTML) { - addMarker(element.id); + addMarker(element.id); board[row][column] = currentMarker } }; @@ -35,6 +41,9 @@ const addMarker = (id) => { ); // @TODO-2: Build a line of code that will set the innerHTML property of the element that was clicked to the "currentMarker" +const row = parseInt(id.charAT(0)) +const column = parseInt(id.charAt(2)) + document.getElementById(id).innerHTML = currentMarker; // @TODO-2.5: MIX & MATCH, You will need the following pieces of code to build that line: // = currentMarker From 6dbd25ee828e096f0dc55c62df165ba94d88b78c Mon Sep 17 00:00:00 2001 From: brookecowey Date: Wed, 22 Feb 2023 20:44:26 -0600 Subject: [PATCH 4/4] added stuff --- scripts.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts.js b/scripts.js index 26e953c..bc2f3cb 100644 --- a/scripts.js +++ b/scripts.js @@ -86,3 +86,7 @@ const resetBoard = () => { squares[i].innerHTML = null; } }; + +msdmfklm + +