HTML and CSS Reference
In-Depth Information
Modify the drop() function to also add "jumponly" to the classList when creating
the new img element by adding the code shown in bold.
// Create a new img on the target location
var newPiece = document.createElement("img");
newPiece.src = droppedPiece.src; =, 1) +;
if (droppedPiece.draggable){
newPiece.draggable = true;
now you'll need to clear the "jumponly" text from the classList when the next
move is completed. You'll do that in the enableNextPlayer() function by adding the
code shown in bold.
function enableNextPlayer(piece) {
// Get all of the pieces
var pieces = document.querySelectorAll('img');
i = 0;
while (i < pieces.length) {
var p = pieces[i++];
// If this is the same color that just moved, disable dragging
if (, 1).toUpperCase() ===, 1).toUpperCase()) {
p.draggable = false;
// Otherwise, enable dragging
else {
p.draggable = true;
now test the application and make sure that each player must alternate turns. Also,
verify that you can make successive jumps.
Search WWH ::

Custom Search