[Javascript Card Counting] - console.log() output very confusing

[Javascript Card Counting] - console.log() output very confusing
0.0 0

#1

Just so I can follow the program and after trying a couple of things, I reduced the code to

var count = 0;

function cc(card) {
  // Only change code below this line
  console.log(card);
  
  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');

just to see how the program is running by default and how the cc() functions get picked to run.

Looking at the console log, the program seems to do a lot more than just run those 5 functions. It just keeps going, like:

counting-cards:7 2
counting-cards:7 3
counting-cards:7 7
counting-cards:7 K
counting-cards:7 A
VM1302:7 2
VM1302:7 3
VM1302:7 7
VM1302:7 K
VM1302:7 A
counting-cards:7 2
counting-cards:7 3
counting-cards:7 4
counting-cards:7 5
counting-cards:7 6
counting-cards:7 7
counting-cards:7 8
counting-cards:7 9
counting-cards:7 10
counting-cards:7 J
counting-cards:7 Q
counting-cards:7 K
counting-cards:7 A
counting-cards:7 3
counting-cards:7 7
counting-cards:7 Q
counting-cards:7 8
counting-cards:7 A
counting-cards:7 2
counting-cards:7 J
counting-cards:7 9
counting-cards:7 2
counting-cards:7 7
counting-cards:7 2
counting-cards:7 2
counting-cards:7 10
counting-cards:7 3
counting-cards:7 2
counting-cards:7 A
counting-cards:7 10
counting-cards:7 K

The first two runs, the values stay the same so I get it. The VM thingy needs to do it’s own thing I suppose. But then, what’s the deal with all those other values after the second loop. They seem to change.

The reason I ask is because I made a copy of a working solution from the forum after trying many things. But the code from the forum won’t pass as valid so I’m on it myself trying to debug it but the debug output is only extra confusing.


#2

FCC checks your code works by running it against a set of predefined values and asserts your code returns expected values.

If you look on the bottom of the left hand side you’ll see:
Cards Sequence 2, 3, 4, 5, 6 should return 5 Bet which is a test
which calls cc(2), cc(3), cc(4), cc(5) and cc(6) and asserts your function returns 5 Bet

resulting in the output you posted above:

counting-cards:7 2
counting-cards:7 3
counting-cards:7 4
counting-cards:7 5
counting-cards:7 6

Then it moves on to the next test case:
Cards Sequence 7, 8, 9 should return 0 Hold
calls cc(7), cc(8) and cc(9) and checks your function returns 0 Hold
which outputs

counting-cards:7 7
counting-cards:7 8
counting-cards:7 9

and so on.

You just need to write a function that will get green for all tests on the left.


#3

Aha! That’s exactly where the confusion came from. Because the assignment suggested you could insert your own cc() functions with their values, it seame up to myself that I would manually have to check all the scenario’s.

But now it’s a lot more clear and I actually made it so the exercise passed!

Thank you @JoolsMcFly!


#4

Yeah, it can be a bit misleading.

Good to hear you passed the exercise, @Olfactorybasic . Onto the next one!


#5

Misleading is exactly what it is. Feels good to be able to proceed :relieved: