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
switch(card){
case 2,3,4,5,6: count++;
break;
case 7,8,9: count: 0;
break;
case 10,'J','Q','K','A': count--;
break;
}
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.
For the rest of you (and for others who are getting started in this and want to try “pair programming”), repl.it 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:
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:
switch(card){
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.
**/
break;
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.
**/
break;
default:
// Of course, we don't need to DO anything for the default case, so we can just...
break;
}
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 repl.it, 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!