0

I'm kinda new to js language, and I have this interesting project. Have you ever played Poker? So, when the user pressed the button, he sees three cards on the table. Then he presses the same 'check' button and he should see the fourth card, and then fifth. How to change the button "job"? I mean. instead of making extra buttons for 4th and 5th card, can I make the game with only one?

vljs
  • 978
  • 7
  • 15
  • You can create a game state flag perhaps? `var gameState = "flop"` then you just add a switch/case statement that checks the game state on click and acts accordingly. You would then update that game state as you move through the program. – Zach M. Sep 01 '17 at 14:31
  • You don't need an event listener to achieve any of this functionality by the way. – Zach M. Sep 01 '17 at 14:33
  • Thank you very much! You've saved me so many lines of code! – vljs Sep 02 '17 at 07:14
  • If i was able to answer your question please remember to flag questions answered. – Zach M. Sep 05 '17 at 12:23

1 Answers1

0

Something like this can get you started:

var gamestate = "";
var update = function() {
  switch (gamestate) {
    case "":
      $('#state').text("A(H) J(D) 10(S)") ;
      gamestate = "flop";
      break;
    case "flop":
      $('#state').text($('#state').text() + " 9(S)");
      gamestate = "turn";
      break;
    case "turn":
      $('#state').text($('#state').text() + " 4(H)");
      gamestate = "river";
      break;
    case "river":
    $('#state').text("");
    gamestate = "";
    break;
  }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="state">

</div>
<a id='clickme' href="javascript:;" onclick="update()">Update</a>

where you have the ...text('info') blocks you would put your dealing cards code based on the game state.

Zach M.
  • 1,188
  • 7
  • 22
  • 46