[SOLVED] Problem with Counting Cards JS code

Hi.

Need some help with this piece of code.

I am not getting the correct results, especially with the alphabets ‘j’, ‘Q’, ‘K’ and ‘A’.

This is the error message ('m getting in the compiler:
“ReferenceError: J is not defined”
var count = 0;

function cc(card) {
// Only change code below this line
var valueBet = “”;

switch (card) {
case 2:
case 3:
case 4:
case 5:
case 6:
count++;
valueBet = count + " Bet";
break;
case 7:
case 8:
case 9:
valueBet = count + " Hold";
break;
case 10:
case ‘J’:
case ‘Q’:
case ‘K’:
case ‘A’:
count–;
valueBet = count + " Hold";
break;
}

return valueBet;
// 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’);
var count = 0;

function cc(card) {
// Only change code below this line
var valueBet = “”;

switch (card) {
case 2:
case 3:
case 4:
case 5:
case 6:
count++;
valueBet = count + " Bet";
break;
case 7:
case 8:
case 9:
valueBet = count + " Hold";
break;
case 10:
case ‘J’:
case ‘Q’:
case ‘K’:
case ‘A’:
count–;
valueBet = count + " Hold";
break;
}

return valueBet;
// 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’);

I don’t play blackjack, BTW.

Help appreciated.

Your code so far

var count = 0;

function cc(card) {
  // Only change code below this line
  var valueBet = "";
  
  switch (card) {
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
      count++;
      valueBet = count + " Bet";
      break;
    case 7:
    case 8:
    case 9:
      valueBet = count + " Hold";
      break;
    case 10:
    case 'J':
    case 'Q':
    case 'K':
    case 'A':
      count--;
      valueBet = count + " Hold";
      break;
  }
  
  return valueBet;
  // 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');

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36.

Link to the challenge:
https://www.freecodecamp.org/challenges/counting-cards

Solved it:

var count = 0;

function cc(card) {
// Only change code below this line
var valueBet = “”;

switch (card) {
case 2:
case 3:
case 4:
case 5:
case 6:
count++;
break;
case 7:
case 8:
case 9:
break;
case 10:
case ‘J’:
case ‘Q’:
case ‘K’:
case ‘A’:
count–;
break;
}

//Added if statement with condition on count
if(count <= 0) {
valueBet = count + " Hold";
}
else if(count >= 0) {
valueBet = count + " Bet";
}

return valueBet;
// Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(2); cc(10); cc(2); cc(7);