Can't get several functions to run in JavaScript.

Hey folks.  I am currently trying to finish up a project that I am doing for school and almost have it complete.  There are 4 functions that are killing me though.  I cannot get them to perform there purpose on the web page.  The functions are labeled showSolution(), hideSolution(), checkSolution(), and uncheckSolution().  I have attached the .js file along with any related files for the project.  Any help would be greatly appreciated.
 
Thanks!
Chris
puzzle.js
hanjie.htm
jpf.css
blackbar.gif
jpf.jpg
ccarter1024Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GaryCommented:
You don't have any code firing when you click the buttons, you need to add an onclick event that calls the particular function.
http://www.w3schools.com/jsref/event_onclick.asp
0
ccarter1024Author Commented:
Hey Gary.  Thanks for the reply.  I thought this was the onclick event...?  Do I have it in the wrong place?

     
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;	
	
}

Open in new window


Thanks!
0
GaryCommented:
I've amended your js to attach directly to the function
window.onload = setPuzzle;

		
var allCells = new Array();

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;
	}

}

function changeColor() {
	
	
	this.style.backgroundColor = (this.style.backgroundColor == "black") ? "white":"black";

}

document.getElementById("solution").onclick = function showSolution() {

	for (var i = 0; i< allCells.length; i ++) {
	   if (allCells[i].className == "dark") {
	   allCells[i].style.background.display = "black";
	   }else{	   
	   allCells[i].style.background.display = "white";
	   }
	 
	 checkCount = "0";
	 }
}

document.getElementById("hide").onclick	=function hideSolution() {

	for (var i = 0; i< allCells.length; i ++) {
		allCells[i].style.background.display = "white";
		}
	checkCount = " ";
}

document.getElementById("check").onclick = function checkSolution() {
	var checkCount = 0;
	
	for (var i = 0; i< allCells.length; i ++) {
		if (allCells[i].className == "dark" && allCells[i].style.background.display == "black") {
		allCells[i].style.background.display = "red";
		} else if (allCells[i].className == "dark" && allCells[i].style.background.display == "white"){
		checkCount ++;
		}
		return checkCount.value;
	}
	
}

document.getElementById("uncheck").onclick = function uncheckSolution() {

	for (var i = 0; i< allCells.length; i ++) {
		if (allCells[i].style.background.display == "red") {
		allCells[i].style.background.display = "black";
		}
	checkCount = " ";
	}
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

ccarter1024Author Commented:
Thanks Gary.  I appreciate your help in this but that didn't work either.  Were you able to get it to work for you when you made these changes?
0
GaryCommented:
Yep working for me, can you paste back what you have in the js file.
0
ccarter1024Author Commented:
window.onload = setPuzzle;

		
var allCells = new Array();

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;
	}

}

function changeColor() {
	
	
	this.style.backgroundColor = (this.style.backgroundColor == "black") ? "white":"black";

}

document.getElementById("solution").onclick = function showSolution() {

	for (var i = 0; i< allCells.length; i ++) {
	   if (allCells[i].className == "dark") {
	   allCells[i].style.background.display = "black";
	   }else{	   
	   allCells[i].style.background.display = "white";
	   }
	 
	 checkCount = "0";
	 }
}

document.getElementById("hide").onclick	=function hideSolution() {

	for (var i = 0; i< allCells.length; i ++) {
		allCells[i].style.background.display = "white";
		}
	checkCount = " ";
}

document.getElementById("check").onclick = function checkSolution() {
	var checkCount = 0;
	
	for (var i = 0; i< allCells.length; i ++) {
		if (allCells[i].className == "dark" && allCells[i].style.background.display == "black") {
		allCells[i].style.background.display = "red";
		} else if (allCells[i].className == "dark" && allCells[i].style.background.display == "white"){
		checkCount ++;
		}
		return checkCount.value;
	}
	
}

document.getElementById("uncheck").onclick = function uncheckSolution() {

	for (var i = 0; i< allCells.length; i ++) {
		if (allCells[i].style.background.display == "red") {
		allCells[i].style.background.display = "black";
		}
	checkCount = " ";
	}
}

Open in new window

0
GaryCommented:
Yep that code is being fired when you click the buttons - what makes you think it is not working?
As to whether the js is doing what is supposed to be doing I don't know
0
ccarter1024Author Commented:
Well the reset button is supposed to reset the grid on the puzzle but it does nothing.  The same with all the other buttons and their corresponding functions.
0
GaryCommented:
A lot of your javascript code is wrong - syntax, returning values to nothing etc
e.g.
allCells[i].style.background.display
should be
allCells[i].style.background

Open in new window

0
ccarter1024Author Commented:
Yeah I know. I was messing around with some syntax to see if I could generate any errors.  Forgot I left that in there.
0
GaryCommented:
Fix all them then see what else is not working.
0
RobOwner (Aidellio)Commented:
I've requested that this question be deleted for the following reason:

The question has either no comments or not enough useful information to be called an "answer".
0
GaryCommented:
Question was answered unfortunately there were other errors, but still this question was given an answer.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.