INFO2180 - Lab 3 (20 Marks) : Tic-Tac-Toe
INFO2180 - Lab 3 (20 Marks) : Tic-Tac-Toe
INFO2180 - Lab 3 (20 Marks) : Tic-Tac-Toe
Tic-Tac-Toe
Tic-tac-toe is typically a paper-and-pencil game for two players, X and O, who take
turns marking the spaces in a 3×3 grid. The player who succeeds in placing three of
their marks in a horizontal, vertical, or diagonal row wins the game.
In this lab we’ll be using HTML, CSS and JavaScript to setup and play a simple game of
Tic-Tac-Toe in a web browser.
You're given files index.html and tic-tac-toe.css. You should get the starter
code by downloading the files from the following link:
https://github.com/uwi-info2180/tic-tac-toe/archive/master.zip
It contains a HTML and CSS file, but these should NOT be modified. You should only
write a script file tic-tac-toe.js in the same directory as these files that provides
all the event handling and behavior to make the Tic Tac Toe game work as specified
below.
Note: That the Inspector, Console and Debugger in the Developer Tools in your Web
Browser can be very useful in helping you to debug your code in this Lab.
NOTE: Ensure you change the URL and use the one that you copied in Step 5 with
your username.
$ cd info2180-lab3
8. You can then type the command ls and you should see a README.md file.
9. In the file add:
# INFO2180 Lab 3
10.Save the file and then at the command line (or Windows Powershell), type:
You should then see that the file has been staged.
It should now mention that there is nothing new to commit and that the working
tree is clean.
$ git push
It may ask you to enter your Github username and password. Enter it and then
press enter. If all goes well you can then view your Github repository on the Github
website and you should see that the file exists on Github with the changes you
made to the file.
14.To see the history of the commits you can run the following command:
$ git log
16.Now download the starter files (if you have not already done so) for the lab at the
following URL:
https://github.com/uwi-info2180/tic-tac-toe/archive/master.zip
17.Unzip and copy the starter files (index.html, tic-tac-toe-bg.png and tic-
tac-toe.css) from the link above into your info2180-lab3 folder that you
cloned in Step 6 and do an initial commit.
$ git add .
$ git commit -m "Added initial starter files"
Hint: It might be helpful to set each div inside the game board to have the provided
CSS class square, using the JavaScript classList property or setAttribute()
method or className property that you learnt in your lecture.
Hint 2: You may also want to ensure you use the onload or DOMContentLoaded
handler.
Once you have completed this exercise, take the opportunity to commit and
push your code to Github.
Hint: You may want to initialize an empty array to keep track of the state of the game
after each square is clicked so that you can use it later to check which user has won.
You can also use the JavaScript innerHTML or textContent property to make the
appropriate X or O show up in the appropriate div.
Once you have completed this exercise, take the opportunity to commit and
push your code to Github.
Exercise 3 - Change the style when you move your
mouse over a square
Now let us see if we can make it a little more interactive by changing the look of the
square whenever a user moves their mouse over a square and then return it to the
original style when the user's mouse leaves the square. You may notice in your tic-
tac-toe.css file that there is a class called hover, which may be helpful.
Once you have completed this exercise, take the opportunity to commit and push your
code to Github.
Hint: You can use the JavaScript innerHTML or textContent property to help you to
place the message in the status div.
Once you have completed this exercise, take the opportunity to commit and push your
code to Github.
Once you have completed this exercise, take the opportunity to commit and push your
code to Github.
Depending on how you coded the previous exercises, you may have a case where if a
user clicks on a square that already has a value then they are able to change what was
there before. Fix this by making it so that a user is not able to change the value of a
square that already has an X or an O.
Once you have completed this exercise, take the opportunity to commit and push your
code to Github.
When you are done and are sure everything is working, switch back to your master
(or main) branch and then merge the changes you made in your "game-
implementation" branch back into your master (or main) branch. Then ensure you
push those changes back to your Github repository.
Submission
Submit this lab via OurVLE using the “Lab 3 Submission" link. The following information
must be submitted:
1. Locate your Github repository URL and Copy the URL. It should be in the format
https://www.github.com/your-user-name/info2180-lab3. For example, if your
username is johndoe, then the URL you will need to submit is https://
www.github.com/johndoe/info2180-lab3.