Basic JavaScript - Counting Cards

How Do I use console.log in code to print and check the card sequence?

console is not printing the answer on screen of the card sequences.

Your code so far

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;
  }
  var holdbet = "Hold";
  if(count > 0){
    holdbet = "Bet";
  }
  return count + " " + holdbet;
  // 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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

Challenge Information:

Basic JavaScript - Counting Cards

I am not sure but console.log (count) is 5 if that`s what your looking for. I used this a lot for checking for bugs, but mostly for string output. Things like bet, fold or stand.

1 Like

Hello @ChattrapatiMonk17

You may wish to check out this response and solution found to a previous question about using console.log for counting cards. I think you will find it, as I did, very good with the response and guidance provided in the post.

Keep up the good progress and happy coding! :sun_with_face:

1 Like

Thanks! Looked up an already answered question on this console(cc()). Here I was adding another count to the console(cc(4)) thus changing the result, now for 1st card sequence i am getting 5 Bet, as well checked through other card sequences as well.

2 Likes

Hi, please check the solution below, its works 100%:

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 7:
case 8:
case 9:
count = count;
break;
case 10:
case โ€˜Jโ€™:
case โ€˜Qโ€™:
case โ€˜Kโ€™:
case โ€˜Aโ€™:
countโ€“;
}
if (count > 0) {
return count + " " + โ€œBetโ€;
} else

return count + " " + โ€œHoldโ€;;
// Only change code above this line
}

cc(2); cc(3); cc(7); cc(โ€˜Kโ€™); cc(โ€˜Aโ€™);