Why does it returns the sum of the callings

So my resolution is this:

var count = 0

function cc(card) {
  // Only change code below this line
  switch (card) {
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
    case 7:
    case 8:
    case 9:
    case 10:
    case "J":
    case "Q":
    case "K":
    case "A":
  if (count > 0) {
    return count + " Bet";
  } else {
    return count + " Hold";
  // Only change code above this line

cc(2); cc(3); cc(7); cc('K'); cc('A');

It works .

The thing is, why does it says in the “result” Cards Sequence 2, 3, 4, 5, 6 should return 5 Bet


Cards Sequence 7, 8, 9 should return 0 Hold


Cards Sequence 10, J, Q, K, A should return -5 Hold


Cards Sequence 3, 7, Q, 8, A should return -1 Hold


Cards Sequence 2, J, 9, 2, 7 should return 1 Bet


Cards Sequence 2, 2, 10 should return 1 Bet

because nothing is added,… you only have a parameter and you test that parameter and call the function 5 times with different arguments… but you are not adding them so why does it says that it needs to RETURN the result… where is that addition happening?

Small typo here above

you are changing the value of count everytime the function is called, aren’t you? you are changing it by adding one or subtracting one (or there is also the chance that it doesn’t change)

that’s the sum result it talks about

Your code has been blurred out to avoid spoiling a full working solution for other campers who may not yet want to see a complete solution. In the future, if you post a full passing solution to a challenge and have questions about it, please surround it with [spoiler] and [/spoiler] tags on the line above and below your solution code.

Thank you.

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

Please use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks are not single quotes.


@snigo not a typo, just the forum rendering two dashes as just one

Alright but still is kind of wrong to say that it return 5 , after those 5 calls if I do a console log of count is 0, where does that 5 returns? Where should I put the console.log to see it?

the function returns the value of count
look at the return statement

to see it you need to call the five functions and then add console.log(count);

for example in the editor you have

cc(2); cc(3); cc(7); cc('K'); cc('A');

if you add console.log(count); below that you get 0 as that how those functions change count
you can also do as follow to see how it changes after each function

console.log(count); // 1
console.log(count); // 2
console.log(count); // 2
console.log(count); // 1
console.log(count); // 0

To see for each card sequence you need to delete these function calls and add those for the card sequence of test

Got it! Thank you so so much!