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 2 of 2 FirstFirst 12
Results 16 to 20 of 20
  1. #16
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,021
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Again, try DEBUGGING!

    I used Chrome and its debugger and immediately got
    Code:
       var currentButton = getElementById(choice);
    Uncaught ReferenceError: getElementById is not defined
    Which is correct. It needs to be document.getElementById()

    But that's not the only problem. You have some nasty logic errors in the code. Clicking on the wrong button ("miss") can cause it to start showing TWO boxes colored, and worse. HINT: You aren't clearing the timeout upon a miss!!! (But there may be other bugs.)

    Oh, and this is UTTERLY BOGUS (the part in red):
    Code:
    document.write('<td width=10%><form><input type="button" value="X" id=' + (y*10+x) + ' this.style.backgroundColor=\'white\' onclick="point()"></form></td>')
    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.

  2. #17
    New Coder
    Join Date
    Jan 2013
    Posts
    26
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Ok, one thing that is nowhere in his notes for me to figure out:

    My coding essentially determines the colored button's color, so I could click any button and it would score according to the colored button. Is there a way to determine if the button clicked matches choice?

  3. #18
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,021
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    THINK about your code!

    You change the color of a button. And then, when a button is clicked, you score *ACCORDING TO WHAT ITS BACKGROUND COLOR IS*.

    So if a button is *NOT* red, green, or blue, clicking on it counts as a MISS.

    Doesn't that do what you are asking for? Or course it does!

    I do *NOT* at ALL understand the point of the BLACK background color, though. If you turn a button BLACK, then if the user clicks on it, that also counts as a MISS! So if a button turns BLACK, the player *MUST* simply wait a full 5 seconds for the next color change. Or get penalized. Right? Is that really what you intended? It works, but it seems like it just slows the game way down.

    Oh...and once you get the game actually working, any player could sit there all day long and never ever miss. So shouldn't you have some magic number that WINS the game? Maybe 50 points?
    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.

  4. #19
    New Coder
    Join Date
    Jan 2013
    Posts
    26
    Thanks
    5
    Thanked 0 Times in 0 Posts
    I intend to redo the timers once the rest of the functions work as I intend to make it harder. The current times are arbitrary. And yes, black is supposed to penalize. It says so in the alert window that gives the rules.

    I've solved all but 1 coding problem. As stated before, no matter which button I click it scores as if I clicked the latest button. I could use a small snippet of code that allows for a test based on button id for the button that calls point. I have finally added functionality to the miss and scoreboard text boxes, and they confirm this. If the current button is red, blue, green, or black, and I click a white square, I still receive 1, 2 3, or -5 (+1 miss) respectively.

    I must thank you all for your help, though. You've helped me more than you probably think.
    Last edited by Reaga; 02-06-2013 at 04:40 PM.

  5. #20
    New Coder
    Join Date
    Jan 2013
    Posts
    26
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Nevermind, I've solved that too, and the page functions perfectly. I simply added a parameter to the point() function, changed the currentButton variable in the point() function to be based on the variable, and each button passes its ID to the point function. Threw in a reload to make sure the game didn't continue after Game Over.

    Feel free to close this topic, mods.


 
Page 2 of 2 FirstFirst 12

Posting Permissions

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