Card counting function

The crap from the video does not work!

The code below does…
??? why

and why do they mislead you with the crap in the video.

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/counting-cards

var 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) return count + " Bet";
  return count + " Hold";
  // Only change code above this line
}

cc(2); cc(3); cc(4); cc(5); cc(6);
console.log(cc(4));

Hello~!

To clarify, are you talking about the video that loads when you choose “Watch a Video” under the “Get Help” option?

I ran the code from the video and it passed all the tests. Which test was it not passing on your end?

yes the code in the watch for help video.
It does not run!

I took pictures of the video and went line for line. it did not run.

var count = 0;

function cc(card) {
  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;
  }

  var holdbet = 'Hold'
  if (count > 0) {
    holdbet = 'Bet'
  }

  return count + " " + holdbet;

}


cc(2); cc('K'); cc(10); cc('K'); cc('A');
console.log(cc(4))

This is the code from the video - does the code you copied line by line match this?

yes i think thats what he did in the video that did not work for me.

This is not exactly what was in the video. Every single character can matter in coding, and you have one character on that line that you should not.

1 Like