Jump to content

davej

Moderator
  • Posts

    3,988
  • Joined

  • Last visited

  • Days Won

    2

Posts posted by davej

  1. I have been playing with something like that. I am thinking that ip addresses and usernames can be added to a timeout table. Each session can also have an "ignore" flag. Each new session gets looked up to see if the username or ip-address is in the timeout table. If it is found in the table then the "ignore" flag is set.

  2. Try experimenting with this and you will see the problem...

    window.onclick = function(e) {
      if (!e.target.matches('.dropbtn')) {
      alert('try to remove show from myDropdown');
        var myDropdown = document.getElementById("myDropdown");
          if (myDropdown.classList.contains('show')) {
            myDropdown.classList.remove('show');
          }
      }else{
        alert('ignore');
      }
    }

     

  3. 4 hours ago, iwato said:

    1) You gave your storage room a name -- namely, $test.
    2) You assigned to the room a certain kind of content -- namely, that of an array $test [...].
    3) You placed content -- namely, 'a' -- in the first box of the array and named the box 'letter1'.

     

    This works in Php, but most programmers use various languages. For example in Javascript this same approach fails...

    <script>
    
    arrtest['letter1'] = 'a';
    arrtest['letter2'] = 'b';
    
    alert(arrtest['letter1']);
    
    </script>

     

  4. Initializing variables can prevent a program from crashing unexpectedly. Isn't that a good enough reason?

    Also Php is very, very forgiving (also known as "idiot-proof"). Why learn bad habits that are poor programming in other languages? Try your code in Javascript and you will see that it fails. In Javascript (and almost all languages) an array must be declared before use.

  5. There are almost always several different ways to approach any programming problem, and that is true here, but you first need to logically understand what you are trying to accomplish, and usually you also want to think of a few simple "test cases" to help you verify your thinking and your code.

     

    Your above question makes me wonder if you logically understand what the code needs to do? How would you write code to detect that at least one square on the board is empty? You can use pencil and paper to help you reason through the problem. My code sample uses a global "turn" variable but you could also test the values on the gameboard. How would you do that?

     

    Also what are you using to write this code? Eclipse? Netbeans? Whatever it is you should learn to use the debugger so that you can single-step through your code.

     

    I would also suggest that you sign up here...

     

    https://www.hackerrank.com/

     

    ...and try working the introductory Java practice problems.

×
×
  • Create New...