Counting Cards, yep its me again

Tell us what’s happening:

Please dont kick me off for asking too many questions!! I havent coded in a long time and im reallllllllyyyy trying to research, fix, and ask for help before just going straight to the solution. thank you!!

Your code so far


var count = 0;

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

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/counting-cards/

almost there for the switch

The switch statement keeps executing till it reaches a break, so if you get 2 then card++ will actually execute five times

Knowing this you can also reduce the repeated code inside the switch
And you need a break after the last case

This is not correct, you may want to review how to concatenate strings with the + operator

‘shiver me timbers’(is what free code camp exclaimed!), i solved it thanks to your help!! Thanks leahleen!

In the future, please do not create multiple threads for the same challenge. Instead, just reply back to your original thread for the challenge and ask additional questions. This reduces clutter on the forum and keeps all your responses/replies in the same thread.

Thank you.

2 Likes