Basic JavaScript Challenge: Counting Cards

My code seems correct according to the solution but when I test it, I don’t get the same output as that recommended in the exercise

Hello team. This is my first post, so apologies in advance for any faux pas I commit in asking my question.
This is my code and I had to get help from the hints in the solution. I understand why this should work and all that is well and good but when I test it using the console.log function, I don’t get the same output as that recommended in the exercise.
For example, according to the problem, "Cards Sequence 10, J, Q, K, A should return the string -5 Hold" But my code returns -1 Hold. I have tested all the sequences suggested and none of them matches the recommended output.

Any idea why that might be?


let count = 0;

function cc(card) {
// Only change code below this line
switch (card) {
case 2:
case 3:
case 4:
case 5:
case 6:
count++;
break;
case 10:
case 'J':
case 'Q':
case 'K':
case 'A':
count--;
break;
}
var betorhold = "Hold";
if (count > 0) {
  betorhold = "Bet";
}

return count + " " + betorhold;
// Only change code above this line
}

cc(2); cc(3); cc(7); cc('K'); cc('A');
console.log(cc (10,'J','Q','K','A'))
console.log(cc (7, 8, 9))
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36

Challenge: Counting Cards

Link to the challenge:

Your code works fine for me. But the console.log’s you are testing have multiple arguments that you are passing at one time, and the function cc(card) as it is set up right now only accepts one argument at a time. Use console.log(card) inside your function after you have these at the bottom, then you should see what is happening.

console.log(cc(2), cc(3), cc(4), cc(5), cc(5));//this should work
console.log(cc (10,'J','Q','K','A'))//these two will only see
console.log(cc (7, 8, 9))//the first argument passed 

You can add to the function like this function cc(card1, card2) and access those arguments if you need to, which will come in handy later on in other sections here. But a google search on arguments would be helpful.

This isn’t how you call the function multiple times. You need a series of function calls

Like this

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.