Basic JavaScript - Counting Cards

Tell us what’s happening:
Describe your issue in detail here.

Your code so far
This is the place where I lost all hope. I dont even know what question to ask in order to ask a question. :sob:
Can anyone point to a good tutorial (already tried the useful programer) that might help me start to understand this one?
Thanks so much :slight_smile:

let 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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Counting Cards

Link to the challenge:

Can you describe to us how you would solve this? What would you do inside the function? You don’t need to use any code. Just describe in words how the function should work.

1 Like

i guess im not really sure how card counting works- so im not sure what the goal of the exercise is… is it that if you end up with a running tally of “x” you would hold and if you have a running tally of “y” you would not hold? like, if your tally of cards is > 0 you would bet and if it is < 0 you would hold?

You really don’t need to know anything about card counting to complete this. The goal of this exercise is to get you to use javascript techniques you have already covered, not to teach you how to count cards :slight_smile:

You only need to understand that the function will be passed certain values (the numbers 2 through 10 and the letters J, Q, K, A. And then the instructions tell you what to do depending on which of those values is passed in, and what to return based on the value of count.

If you understand the above then you have enough to complete this challenge. So now you need to explain what you would do inside the function in order to complete it.

1 Like

ok- so i would check the value of each of the cards that are passed into the function.

and then based on the values of the cards that are passed into the function- the function will then return a statement?

Yes, you check the value passed into the function, and you will return a value, but there is something else you need to do before you return a value.

have some way of keeping the count?

“It will receive a card parameter, which can be a number or a string, and increment or decrement the global count variable according to the card’s value (see table).

The count variable defined above the function is the way to keep track of the count.

ok so i would start there. let count = 0;

Yes, that exact code is already there for you to use :slight_smile:

lol ive been staring at this thing so long i kind of havent even looked at the code - ok so my bad… haha and thank you for helping me btw- ok so let count = 0, then create the function? and the function could loop though each card in an array?

I’m not going to give you much hints on how to actually do this because I don’t want to deprive you of the fun of figuring it our on your own. But I will tell you that my solution would probably not involve using an array.

dang! how else would you list out all the cards tho?

oh- ok- going back to the switch tutorials lol

still need help solving the exercise?

Please start your own post explaining what you need help with and showing us your current code.