Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Count Change Cards
- +1 2, 3, 4, 5, 6
- 0 7, 8, 9
- -1 10, 'J', 'Q', 'K', 'A'
- 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.
- Example Output
- -3 Hold
- 5 Bet
- Hint
- Do NOT reset count to 0 when value is 7, 8, or 9.
- Do NOT return an array.
- Do NOT include quotes (single or double) in the output.
- CODE:
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- var count = 0;
- function cc(card) {
- // Only change code below this line
- if (card = 2) {
- count++;
- return count + " Bet";
- }
- else if (card = 3) {
- count++;
- return count + " Bet";
- }
- else if (card = 4) {
- count++;
- return count + " Bet";
- }
- else if (card = 5) {
- count++;
- return count + " Bet";
- }
- else {
- count++;
- return count + " Bet";
- }
- if (card = 7) {
- count + 0;
- return count + " Hold";
- }
- else if (card = 8) {
- count + 0;
- return count + " Hold";
- }
- else {
- count + 0;
- return count + " Hold";
- }
- if (card = 10) {
- count--;
- return count + " Hold";
- }
- else if (card = 'J') {
- count--;
- return count + " Hold";
- }
- else if (card = 'Q') {
- count--;
- return count + " Hold";
- }
- else if (card = 'K') {
- count--;
- return count + " Hold";
- }
- else {
- count--;
- return count + " Hold";
- }
- // Only change code above this line
- }
- // Add/remove calls to test your function.
- // Note: Only the last will display
- cc(2); cc(3); cc(7); cc('K'); cc('A');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement