HELP!~I am stucked at JS counting card challenge

A walkthrough helps when code produces unexpected results - a good walkthrough is when you pretend to be the computer and simply execute the code line by line variable by variable without explanation or thinking - in fact trying to think or understand during a walkthrough is counterproductive

Here’s your code with line numbers

1. if (card >= 2 && card <= 6) {
2.   return count++;
3. } else if (card==10 || typeof card==="string") {
4.   return count--; 
5. } if (count<=0) {
6.  return (count+" Hold");
7. } else { 
8.  return (count+" Bet");
9. }
10. return "Change Me";

Here’s my walkthrough for the CC(2) through CC(6) test case - this is not code

count=0

CC(2):
1: card=2 -> true
2: count=0, return 0, count=1

CC(3):
1: card=3 -> true
2: count=1, return 1, count=2

CC(4):
1: card=4 -> true
2: count=2, return 2, count=3

CC(5):
1: card=5 -> true
2: count=3, return 3, count=4

CC(6):
1: card=6 -> true
2: count=4, return 4, count=5

I hope this helps you fix your code

1 Like