Tell us what’s happening:
Something odd is happening during two of the FCC tests
- Cards Sequence 2, J, 9, 2, 7 should return “1 Bet”
- Cards Sequence 2, 2, 10 should return “1 Bet”
CONSOLE LOG —
My Console Log shows the correct outputs but for some reason FCC marks this as wrong.
Screenshot:
TEST ONE - Cards Sequence 2, J, 9, 2, 7
card given: 2. Current count is 0. Incrementing count. New count 1 VM1368:16
1 Bet VM1368:36
card given: J. Current count is 1. Reducing count by 1. New count 0 VM1368:39
0 Hold VM1368:23
card given: 9. Current count is 0. Do Not Increment or Reduce count. Count is 0 VM1368:26
0 Hold VM1368:14
card given: 2. Current count is 0. Incrementing count. New count 1 VM1368:16
1 Bet VM1368:23
card given: 7. Current count is 1. Do Not Increment or Reduce count. Count is 1 VM1368:14
TEST TWO - Cards Sequence 2, 2, 10 should return “1 Bet”
card given: 2. Current count is 0. Incrementing count. New count 1 VM1368:16
1 Bet VM1368:14
card given: 2. Current count is 1. Incrementing count. New count 2 VM1368:16
2 Bet VM1368:36
Card given: 10. Current count is 2. Reducing count by 1. New count 1
I have a feeling is a bug or a simple typo but i cant seem to find it. Any help or insight is appreciated. Thank you.
Your code so far
var count = 0;
function cc(card) {
// Only change code below this line
switch (card) {
case 2:
case 3:
case 4:
case 5:
case 6:
console.log("card given: " + card + ". Current count is " + count++ + ". Incrementing count. New count " + count);
if (count >= 0) {
console.log(count + " Bet");
return count + " Bet";
}
break;
case 7:
case 8:
case 9:
console.log("card given: " + card + ". Current count is " + count + ". Do Not Increment or Reduce count. Count is " + count);
if (count == 0) {
console.log(count + " Hold");
return count + " Hold";
}
break;
case 10:
case "J":
case "Q":
case "K":
case "A":
console.log("card given: " + card + ". Current count is " + count-- + ". Reducing count by 1. New count " + count);
if (count <= 0) {
console.log(count + " Hold");
return count + " Hold";
}
break;
}
// Only change code above this line
}
// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc('J'); cc(9); cc(2); cc(7);
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
.
Link to the challenge:
https://www.freecodecamp.org/challenges/counting-cards