You'll be making a nonogram puzzle (Hanjie, Number Grid, Pi-Cross, etc) and allow the user to play the game by filling, unfilling, or clearing tiles of a nonogram puzzle. You do not need to know how these puzzles work to complete the project.
Complete the UI of a nonogram puzzle. Practice DOM manipulation using JavaScript by completing several functions.
We have provided the HTML (project.html
) and CSS (project.css
) that you will need for this project. You will be writing JavaScript code in a file called project.js
and make it possible to play the puzzle.
To complete this project, students should have the following:
- Basic understanding of JS (arrays, objects, for loops, functions, if statements, this)
-
Download this project from GitHub.
-
Open the JavaScript file (
project.js
). You will be writing JavaScript code here. -
Open
project.html
on your web browser to understand what you will be adding functionality to.
If a user clicks on any tile, an alert pops up with a message. Complete the function setUpTiles
by:
- Selecting every tile in the grid and implementing an
onclick
event handler to each tile.
(Hint: Every tile in the grid has the class .box
)
- If any tile is clicked on, an alert pops up with the message "You clicked a tile!". Use the
alert
function.
If a user clicks on any tile, it will turn black and become filled. You can complete this by updating and completing two functions:
- Complete the function
changeBoxMark
so that a single tile is filled in when a user clicks on it. There is a class,.filled
, that handles the styling for you in thecss
file.
(Hint: Utilize the function's this
keyword.)
- Update the function
setUpTiles
so that thechangeBoxMark
function is called whenever a single tile is clicked on. You should also remove the alert pop up insetUpTiles
function.
If a user clicks on a white tile, it will turn black (or become filled). If a user clicks a black tile, it will turn white (or become unfilled). Modify your changeBoxMark
function so that toggling between unfilled and filled tiles is possible.
- You will need to implement
if-else
statements in thechangeBoxMark
function to change black tiles to white tiles and vice versa. There is no "unfilled" class for the tiles. You can clear a filled tile by simply removing the.filled
class.
When the "Clear" button is clicked, the user will be asked to confirm their choice and if the choice is "OK" all filled tiles will be unfilled.
- Complete the function
clearPuzzle
by selecting every tile and removing the class.filled
(Hint: Every tile in the grid has the class .box
)
- Add a
confirm
message in the functionclearPuzzle
so that the user has a second chance to decide if they want to clear their tiles. The message should say "Are you sure you want to clear the puzzle?". The tiles will clear only if the users confirmsOK
.
Original project made by Paul Cleverdon and his team of developers (2018).