Link to home
Start Free TrialLog in
Avatar of tfaofporter
tfaofporter

asked on

problem with a js/html assignment

I can't find the error as to why this code doesn't work. Ive attached all the files related to the project
hanjie.html
jpf.css
puzzle.js
blackbar.gif
jpf.jpg
Avatar of Gary
Gary
Flag of Ireland image

And the problem is...?
Avatar of tfaofporter
tfaofporter

ASKER

the problem is that the js file isn't working when I select an action on the page such as select a cell
Move the puzzle.js script tag to the bottom of the page and replace the following two functions in that js with this

function setPuzzle() {
	var puzzleTable = document.getElementById("puzzleCells");
	 allCells= puzzleTable.getElementsByTagName("td");
	for (var i = 0; i< allCells.length; i ++) {
		allCells[i].style.background.display = "white";
		allCells[i].onclick = changeColor;
	}
	document.getElementById("solution").onclick = showSolution;
	document.getElementById("hide").onclick	= hideSolution;
	document.getElementById("check").onclick = checkSolution;
	document.getElementById("uncheck").onclick = uncheckSolution;	
}

function changeColor() {
	if (this.style.backgroundColor == "black") {
	this.style.backgroundColor = "white";
	}else{
	this.style.backgroundColor = "black";
	}
}

Open in new window

not sure what you mean by:
Move the puzzle.js script tag to the bottom of the page
Cut this from the top of the page
<script src="puzzle.js" type="text/javascript"></script>

and place paste it after the closing </html>
the only thing that works is the ability to select a cell and turn the color from white to black none of the other of the javascript functions are working.
GaryC123, are you there?
Where did you get this script from because all the js is wrong.
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'm a novice at script...I'm just learning javascript. thanks