Counting Cards

Tell us what’s happening:

hey @snowmonkey could we pair program for this one? thanks! Kerri

Your code so far

var count = 0;

function cc(card) {
  // Only change code below this line
    case 2,3,4,5,6: count++;
    case 7,8,9: count: 0;
    case 10,'J','Q','K','A': count--;
  return "Change Me";
  // 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:

I also wish the syntax could be simplified like this but this isn’t valid.

You will need to lay them out like this to accomplish similar effect.

case 2:
case 3:
case 4:

Example code here.

This is also not valid
Here where you don’t need to change count you can just not write anything or write count = count

Hey I guess Im really lost on this one. Its confusing the heck out of me.

For the rest of you (and for others who are getting started in this and want to try “pair programming”), not only lets you try out your code on a wide variety of software platforms, but they have a really powerful “multiplayer” feature! I’ve used this a number of times for a pairs programming teachable moment, and I’m totally willing to set one up at any point. Except, sadly, eleven hours ago, when I was sanding joint compound at my day job.

Now, @Kittles04, there were a few suggestions above to note:

  1. a switch/case statement is evaluated exactly the same way as an if statement: one thing can only be tested against one thing. case 2, 3, 4, 5, 6: is going to cause issues, as was said above. Instead, you’d have to do:
  case 2:
  case 3:
  case 4:
  case 5:
  case 6:
     * Whatever code we put here will handle all cases of 2 through 6. Here, we can increment
     *   count, we can do whatever, and THEN WE HAVE TO BREAK.
     *   the reason for the break is, we don't want to keep handling all the OTHER cases.
     *   Note that I'm not going to create cases for 7, 8 or 9, as the value doesn't change.
  case 10:
  case 'J':
  case 'Q':
  case 'K':
  case 'A':
     * Here we handle the 10 - A cases. We didn't have to do anything with the 7, 8, 9 cases
     *   as they do not change the value of count. So here, we can decrement count, and we
     *   still want to break! Why do we need to break? Because, we also have ONE more case
     *   to handle: everything else. Yup. In case card is anything else, it's good practice to create
     *   a default case.
    // Of course, we don't need to DO anything for the default case, so we can just...
  1. When we return something from this, we need to use the value of count that we just updated in that funky switch/case we made. If count is telling us “Hey, I’m negative!” we need to send ONE thing, but if it says “Hey, I’m positive!” we need to send something else.

I have set up a, if you want to use it to play. And if you are interested in pairing to work on this, or if someone wants to pair with you, you can use my repl to play multiplayer!

Here’s the link to the current repl:

1 Like

You can follow the next parts of the story

Thanks, I joined repl. I am working on one today that I’ve been working on all morning:

I usually work 6:30 AM to 11:30 AM Pacific Time. Do you want to do pair programming with me during that time?

If you need help tomorrow I can help you for a couple of hours at that time, I am curious about the multiplayer feature

1 Like

Great! I would love to. I use slack a lot to pair program or else i use skype.

You can join an unofficial study slack for fcc here: slack invite link