Basic JavaScript - Counting Cards

Can not figure out what I’m doing wrong.
To explain briefly, we are supposed to write a program that keeps track of the ‘count’ in blackjack. 2-6 raises the count by 1, 7-9 keeps the count the same, and 10-Ace lowers the count by 1. The program should return the count, along with either “Bet” (if the count is positive) or “Hold” (if the count is negative).

‘answer’ is what I named the variable for ‘Bet’ or ‘Hold’.


let count = 0;

function cc(card) {
  
switch (card) {
  case 2:
  case 3:
  case 4:
  case 5:
  case 6:
    count = count + 1;
    break;
  case 7:
  case 8:
  case 9:
    count = count + 0;
    break;
  case 10:
  case 'J':
  case 'Q':
  case 'K':
  case 'A':
    count = count - 1;
    break;
}
   
var answer = '';
if (count < 0) {
    answer = 'Bet';
  }
  else if (count >= 0) {
    answer = 'Hold';
  }
  
  return (count + ' ' + answer);

  return "Change Me";
  // Only change code above this line
}

cc(2); cc(3); cc(7); cc('K'); cc('A');

Challenge: Basic JavaScript - Counting Cards

Link to the challenge:

for anyone reading this, I mixed up the ‘greater than’ and ‘less than’ for ‘Hold’ and ‘Bet’.
:rofl:

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.