alert
at the top of your file and/or function and see if it shows up.background-image
property on the tiles properly in your JS DOM code. Try alert
ing the exact string you're setting it to. Remember that it should be a string storing a pair of values with units after them, such as "100px 300px". Also remember that the offsets you need to shift the image behind each tile may be negative, such as "-100px -300px". Note that there isn't a comma in the string; it is two integers, each with "px" after, separated by a space. You may have to build said string using variables' values.
left
/top
style valuesTry to make your code read more like English. "If I can move this square, move it to the location of the empty square." If your code doesn't have methods for those things, you need more procedural breakdown of the problem.
movablepiece
that you should apply to such squares.
div
element to represent the empty square in my puzzle?
.html
file. But you can use the JS DOM to add an empty div
if you like, if it makes your code easier to write.
for (~200 times): figure out all the squares that neighbor the empty square. put them into an array or something. randomly choose an element of that array. swap the randomly chosen element with the empty square.
onclick
handler function, without having to actually click on the square.
onclick
event. But just turn your click response code into a helper function, and call that.