Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,19 @@ <h1>Welcome to Tic Tac Toe</h1>
<table>
<tr>
<!-- the onclick calls a function called "handleClick" and passes itself to it -->
<td id='top-left' onclick="handleClick(this)" ></td>
<td id='top-middle'></td>
<td></td>
<td id='top-left' onclick="handleClick(this)"></td>
<td id='top-middle' onclick="handleClick(this)"></td>
<td id='top-right' onclick="handleClick(this)"></td>
</tr>
<tr>
<td id='mid-left' onclick="handleClick(this)"></td>
<td id='mid-middle' onclick="handleClick(this)"></td>
<td id='mid-right' onclick="handleClick(this)"></td>
</tr>
<tr>
<td id='bottom-left' onclick="handleClick(this)"></td>
<td id='bottom-middle' onclick="handleClick(this)"></td>
<td id='bottom-right' onclick="handleClick(this)"></td>
</tr>
<!-- @TODO create new rows and cells for the rest of your TTT board. -->
<!-- @TODO give each new cell an id & an event listener to call the "handleClick" function -->
Expand Down
19 changes: 5 additions & 14 deletions scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
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" 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) => {
Expand All @@ -27,15 +25,6 @@ const handleClick = (element) => {
}











// this function places the "currentMarker" inside the HTML element that was clicked and calls the "changeMarker" function.
const addMarker = (id) => {

Expand All @@ -50,8 +39,9 @@ const addMarker = (id) => {
// .getElementById(id)
// document
// .innerHTML
document.getElementById(id).innerHTML = currentMarker

changeMarker()
changeMarker()
}


Expand Down Expand Up @@ -83,10 +73,11 @@ const changeMarker = () => {

// 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

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")
Expand Down