Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 3 123 LastLast
Results 1 to 15 of 34
  1. #1
    New Coder
    Join Date
    Feb 2012
    Location
    East Tennessee
    Posts
    56
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Question This hanjie puzzle is giving me fits!

    Does anyone know how to make these things work? I have to make this hanjie puzzle and I have at least gotten the black squares to display. I have worked through all the directions three times and run it through the Firebug. I don't understand what it is asking for and don't know how to change the code to make this work, someone please help me!

    Code:
    window.onload = setPuzzle;
    
    var allCells = new Array();
    
    function setPuzzle() {
        var puzzleTable = document.getElementById("puzzleCells");
    
        allCells = document.getElementsByTagName("td");
        for (var i =0; i < allCells.length; i++) {
        allCells[i].style.backgroundColor = "white";
        allCells[i].onclick = changeColor;
        }
        document.getElementById("solution").onclick = showSolution;
        document.getElementById("hide").onclick = hideSolution;
        document.getElementById("solution").onclick = showSolution;
        document.getElementById("check").onclick = checkSolution;
        document.getElementById("uncheck").onclick = uncheckSolution;
    
    }
    
    
    function changeColor(){
        this.style.backgroundColor = (this.style.backgroundColor == "black") ? "white" : "black";
    }
     function showSolution(){
        for(var i=0;i<allCells.length; i++) {
    
        if(allCells.className == "dark"){
        allCells[i].style.backgroundColor = "black";
        } else {
        allCells[i].style.backgroundColor = "white";
        }
      }
        checkCount = 0;
    }
    
     function hideSolution() {
        for(var i=0;i<allCells.length; i++) {
        allCells[i].style.backgroundColor = "white";
        }
        checkCount = " ";
     }
    
    function checkSolution() {
    	var checkCount = 0;
    	for (var i = 0; i< allCells.length; i++) {
    		if (allCells[i].style.backgroundColor == "black" && allCells[i].className != "dark") {
    		allCells[i].style.backgroundColor = "red";
    		} else if (allCells[i].className == "dark" && allCells[i].style.backgroundColor == "white"){
    		checkCount++;
    		}
    		return checkCount.value;
    	}
    }
    
    function uncheckSolution() {
    	for (var i = 0; i< allCells.length; i++) {
    		if (allCells[i].style.backgroundColor == "red") {
    		allCells[i].style.backgroundColor = "black";
    		}
    	    checkCount = " ";
    	}
    }

  • #2
    New Coder
    Join Date
    Feb 2012
    Location
    East Tennessee
    Posts
    56
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Firebug:

    Firebug says:
    Use of getAttributeNodeNS() is deprecated. Use getAttributeNS() instead. I have no idea what to change or how. When I tried looking it up at W3schools.com I just got more confused, someone please help me!

  • #3
    New Coder
    Join Date
    Feb 2012
    Location
    East Tennessee
    Posts
    56
    Thanks
    7
    Thanked 0 Times in 0 Posts

    HTML attached

    I have uploaded the HTML file in txt form, I am hoping you coding gurus will help me become another one.

    Sincerely,
    Janice Paul
    Attached Files Attached Files

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,910
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    I don't see what is wrong with your code except that you have repeated

    document.getElementById("solution").onclick = showSolution;

    which may confuse the browser.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Quote Originally Posted by jdpaul View Post
    Firebug says:
    Use of getAttributeNodeNS() is deprecated. Use getAttributeNS() instead. I have no idea what to change or how. When I tried looking it up at W3schools.com I just got more confused, someone please help me!
    Don't worry about this. It's a peculiarity of FireBug. I get it all the time and I never use getAttributeNodeNS().
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Change your <table> for the puzzle, thus:
    Code:
    <table border="1" id="puzzleCells">
    Now you can see your problem. Your cells are all just 1 by 1 pixels, apparently.

    You made a fatal mistake, embedding one <table> in another. You need to do it *ALL* with a *SINGLE* <table>, so that the numbers on the top and side line up with the cells in the middle.

    You've made it way way too hard on yourself, designing the <table>s the way you have.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    New Coder
    Join Date
    Feb 2012
    Location
    East Tennessee
    Posts
    56
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Unhappy dang it! nothing has made a difference yet ... GRR!

    I thought I was starting to get this when you guys said there was nothing wrong with it, I took it back through IE and Firebug after changing the parts you advised to ... same result :P I know I am no master of JavaScript, but it shouldn't be brain-surgery either should it? I guess I will put it online where you can see what it doesn't do right, etc. I hope w/ a couple of experienced eyes to assist me, maybe I can find the goof in my code. I thought it should show the Solution and I have a picture example with part of the puzzle blocks in red. By the way, it was totally NOT my idea to put a table within a table!!!! I promise! I was taught to write Web pages MUch better than that. I didn't make up the HTML or JavaScript, I am just supposed to make it work. Yeah, right ...

    Please help me,
    Janice
    Attached Files Attached Files

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Oh, silly me...I don't have your CSS files so I can't see the page as you are seeing it.

    Without CSS, the cells in the inner table are 1x1 pixel in size.

    How about putting it up live, so we can see it?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #9
    New Coder
    Join Date
    Feb 2012
    Location
    East Tennessee
    Posts
    56
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Unhappy duh! sorry!

    I am putting what I have online now ...
    Janice's JavaScript
    Janice

    I am gonna cry! It just keeps getting worse no matter what I do.

  • #10
    New Coder
    Join Date
    Feb 2012
    Location
    East Tennessee
    Posts
    56
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Question I have requested the missing files ...

    I don't know what else to do ... I think there are supporting jpg files missing because if you read the very top of the CSS file it says there are supposed to be three jpg files that I can't find. If or when I find them, maybe we can make this work .. or am I totally lost out there in the tall weeds?

    Befuddled,
    Janice

  • #11
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Okay, so what doesn't work, other than "Show Solution" and "Check Solution"??

    It seems that clicking on the cells works fine. They turn black (or white if already black).

    Irrelevant (and irreverant) comment:

    I think it is funny (in a sad sort of way) that the Japanese get credit for this puzzle type. Same as they get credit for Sudoku and Kakuru. Anybody who is a long time puzzle fan knows that all three of these types of puzzles appeared in the various Dell and Penny Press puzzle magazines in the USA long before they every appeared in Japan. Heck, the guy who created Sudoku (of course it wasn't known by that name...I think it was "Number place" but can't swear to that) *DIED* only a couple of years after Sudoku finally appeared in Japan. I remember doing his puzzles at least 20 years ago and probably more than that.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #12
    New Coder
    Join Date
    Feb 2012
    Location
    East Tennessee
    Posts
    56
    Thanks
    7
    Thanked 0 Times in 0 Posts

    hehe :)

    You are sooo right about the puzzles! I have found that there has been a major over-sight with this program. There are at the moment 4 files I know of missing
    there's a style sheet missing and 3 jpgs. I have made this over-sight known to the people who should have never let it happen to begin with and now have to wait for them to get off their duffs and get the dang files.

    What doesn't work work is exactly what you said, w/o the jpgs & style sheet, I see no way to make this one work. :P
    I am disgusted w/ the lack ...

    Janice

  • #13
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    LOL! Well, the GOOD news is that it's not your fault.

    The BAD news is that your head is sore now from all that banging against the wall.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #14
    New Coder
    Join Date
    Feb 2012
    Location
    East Tennessee
    Posts
    56
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Question aspirin plez?

    Yeah, well, I like to do my work as correctly as possible, as early as possible and this dumb thing happening is not helping me. So, without having those three image files and the missing style sheet ... am I to understand correctly that the JavaScript code does not make any of the tiles change to red?

    Still trying ...
    Janice

  • #15
    New Coder
    Join Date
    Feb 2012
    Location
    East Tennessee
    Posts
    56
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Thumbs down more aspirin PleasE!!!

    I tried to get the missing files today and to my utter horror I was told that they weren't needed and it was good enough the way it was. ;\ I don't like this at all. I feel like I had to do a half-*** job because there are files missing. Pooey!!! Is there a way to make the JavaScript code make some of the tiles red? I really wanted this one to turn out right. *pout*

    Janice


  •  
    Page 1 of 3 123 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •