Advertisement
ndburrus

Counting Cards @mhpoblet

Aug 13th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. // Counting Cards
  2. // @mhpoblet
  3.  
  4.  
  5.  
  6. var count = 0;
  7.  
  8. function cc(card) {
  9. // Only change code below this line
  10. if (card >= 2 && card <= 6) {
  11. count++; // this is correct/nice! we want to adjust the count variable per card value received.
  12. // for cards 2 through 6, this does this nicely :) . we need to make the appropriate
  13. // adjustment for the other cases.
  14. return count + " Bet"; // ok, let's handle the result/return/s outside of the conditional.
  15. // this means that we take the rerun/s & count manipulation out of
  16. // the if/else statement.
  17. // the only thing we want to accomplish with the conditional is the
  18. // handling of the count variable, which needs to be calculated
  19. // (or adjusted five times) based on the card values received.
  20. } else if (card >= 7 && card <=9) {
  21. return count + " Hold";
  22. } else {
  23. count--;
  24. return count + " Hold";
  25. }
  26.  
  27. // here, at the conclusion of the conditional iterations, we should have our final count variable. we
  28. // can now handle the logic & output/return. we can use another conditional (if/else, if you want to) to
  29. // evaluate the card value being a) positive, or b) zero or negative.
  30.  
  31. // as return inside of a conditional are sometimes an issue, we can use a variable assignment (of hold, bet) inside
  32. // the conditional. once we have the desired assignment to the variable count, we can provide the output (count and betting
  33. // action).
  34.  
  35. return "Change Me";
  36. // Only change code above this line
  37. }
  38.  
  39. // Add/remove calls to test your function.
  40. // Note: Only the last will display
  41. cc(10);cc(2);cc(2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement