Counting Cards - Negatives pass but positives fail

Hi, I am very new to Java Script and am having a little trouble with the below.

I have looked through the hints and managed to get it to the point where the zero and negative outcomes will pass the tests, but the positive outcomes fail, although they use the same set up? I can get the positive outcome to pass and the negatives to fail by commenting out one or the other.

I have narrowed it down to the way I am asking it to decide/display the final count, If I add an else if or else instead of the second if I get an error “SyntaxError: unknown: Unexpected token” on the else, see below:


if (count > 0); {
     return (count + " Bet");
  }
else if (count <= 0); {
     return (count + " Hold");
  }

Also tried:

if (count > 0); {
     var play = " Bet";
  }
else if (count <= 0); {
     var play = " Hold";
  }
return (count + play);

I have a solution that works but it can’t be the best way to do it. In a real card counting scenario you would have to add way more case + & - for it to work

let count = 0;

function cc(card) {
  // Only change code below this line
  switch (card) {
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
      count++;
      break;
    case 10:
    case "J":
    case "Q":
    case "K":
    case "A":
      count--;
      break;
  }
  switch (count) {
    case -5:
    case -4:
    case -3:
    case -2:
    case -1:
    case 0:
      return (count + " Hold");
      break;
    case 1:
    case 2:
    case 3:
    case 4:
    case 5:
      return (count + " Bet");
      break;
}

  // Only change code above this line
}

Original code so far, this is the one I tried the else and else if on:

let count = 0;

function cc(card) {
  // Only change code below this line
  switch (card) {
    case 2:
    case 3:
    case 4:
    case 5:
    case 6: 
      count++;
      break;
    case 10:
    case "J":
    case "Q":
    case "K":
    case "A":
      count--;
      break;
  }
    if (count > 0); {
     var play = " Bet";
  }
    if (count <= 0); {
     var play = " Hold";
  }
  return (count + play);

  // Only change code above this line
}

cc(2); cc(3); cc(4); cc(5); cc(6);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.1370.42

Challenge: Basic JavaScript - Counting Cards

Link to the challenge:

You should not add a semi-colon after the if condition. Rewrite it to look like this without semicolons

if (something) { 
1 Like

Your solution using switch passes all the tests.

Amazing, thank you once again
Have spent a long time staring at this and didn’t see this :exploding_head:

1 Like

Hi Randell, yes it does but I wanted to understand why the other solutions were not working because to my little understanding they should have.

I only resorted to the switch method after a lot of head scratching and trying to figure out what was happening. The switch method seemed overly complicated, and I was keen to learn what was going on not just get through the lesson for the sake of getting thorough it.