Counting Cards Excercise

Hello All, I have a question about the counting cards exercise. I believe my question is more conceptual. with my function cc(card) I don’t understand if the card parameter is an array or just a single character? in the exercise I believe the test calls are for multiple calls of the cc(card) function with a single character passed as the card argument, here are the test inputs given for example:

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

THIS is not my code but someone’s example to the answer.

let count = 0;
function cc(card) {
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;
 }
 if (count > 0) {
 return count + " Bet";
  } else {
 return count + " Hold";
 }

I copy pasted there code to run it on my editor to see what everything is doing and with this code and test examples given im getting no output. Why? however when i copy paste this code into the exercise replicator i get a passing course. I didnt want to have to look at someone else code i just don’t understand this question. Is the argument to be passed in a single character or an array?

  **Your code so far**

var count = 0;

function cc(card) {
// Only change code below this line


return "Change Me";
// Only change code above this line
}

cc(2); cc(3); cc(7); cc('K'); cc('A');
  **Your browser information:**

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

Challenge: Counting Cards

Link to the challenge:

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.

You can also 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 (’).

1 Like

Firstly, I highly recommend against reading solutions other people have written before solving the challenge for yourself. I recommend asking questions first.

Anyways…

The input to be passed in is a single number or character representing the face value of a card. But count is a global variable, so repeated calls to the function will change the behaviour of the function.

I’m not sure what you mean by getting no output. The copied code certainly has an output, given by the return statements. In order to see the output, you should console.log() it.

1 Like

yes correct I will console.log() to see output. And you are right I should and will from now on ask questions on my own code before asking questions about someone else’s solution, my apologies! and thanks for clarifying, you answered my question which is that the parameter card is a single character and not an array. Thanks!

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