Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. Count Change Cards
  2. +1 2, 3, 4, 5, 6
  3. 0 7, 8, 9
  4. -1 10, 'J', 'Q', 'K', 'A'
  5.  
  6. You will write a card counting function. It will receive a card parameter, which can be a number or a string, and increment or decrement the global count variable according to the card's value (see table). The function will then return a string with the current count and the string Bet if the count is positive, or Hold if the count is zero or negative. The current count and the player's decision (Bet or Hold) should be separated by a single space.
  7.  
  8. Example Output
  9. -3 Hold
  10. 5 Bet
  11.  
  12. Hint
  13. Do NOT reset count to 0 when value is 7, 8, or 9.
  14. Do NOT return an array.
  15. Do NOT include quotes (single or double) in the output.
  16.  
  17. CODE:
  18. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  19.  
  20.  
  21. var count = 0;
  22.  
  23. function cc(card) {
  24. // Only change code below this line
  25.  
  26. if (card = 2) {
  27. count++;
  28. return count + " Bet";
  29. }
  30. else if (card = 3) {
  31. count++;
  32. return count + " Bet";
  33. }
  34. else if (card = 4) {
  35. count++;
  36. return count + " Bet";
  37. }
  38. else if (card = 5) {
  39. count++;
  40. return count + " Bet";
  41. }
  42. else {
  43. count++;
  44. return count + " Bet";
  45. }
  46. if (card = 7) {
  47. count + 0;
  48. return count + " Hold";
  49. }
  50. else if (card = 8) {
  51. count + 0;
  52. return count + " Hold";
  53. }
  54. else {
  55. count + 0;
  56. return count + " Hold";
  57. }
  58. if (card = 10) {
  59. count--;
  60. return count + " Hold";
  61. }
  62. else if (card = 'J') {
  63. count--;
  64. return count + " Hold";
  65. }
  66. else if (card = 'Q') {
  67. count--;
  68. return count + " Hold";
  69. }
  70. else if (card = 'K') {
  71. count--;
  72. return count + " Hold";
  73. }
  74. else {
  75. count--;
  76. return count + " Hold";
  77. }
  78. // Only change code above this line
  79. }
  80.  
  81. // Add/remove calls to test your function.
  82. // Note: Only the last will display
  83. cc(2); cc(3); cc(7); cc('K'); cc('A');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement