Counting Cards this is hard could use some help

Tell us what’s happening:

I made what I think is right. To solve the problem (yes i know it’s terrible)
Could you guy’s be kind enought to leave some feedback?

Your code so far


var count = 0;

function cc(card) {
  // Only change code below this line
  para ="card" > 
  var count
  if postive (2, 3, 4, 5, 6)
  print "Bet"

else if 
print (7, 8, 9 10, 'J', 'Q', 'K', 'A' )
  return "hold " 


  // 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');

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.2 Safari/605.1.15.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/counting-cards

Are you trying to write a solution in python?
Honestly, I am confused by every line of this.

2 Likes

well actually it was suppose to be javascript…

para ="card" > 

What do you expect this line of code to do?

  var count

Why are you declaring a local version of count?

if postive (2, 3, 4, 5, 6)

Where is the method positive defined? Why is there a space before the parentheses?

  print "Bet"

This isn’t JavaScript.

else if

Where is the rest of this? Where is the condition logic?

print (7, 8, 9 10, 'J', 'Q', 'K', 'A' )

This is different than your earlier line with “print” in it. Why? This line is also not valid JavaScript.

  return "hold " 

Why are you returning this value?

para ="card" > 

What do you expect this line of code to do?
You will write a card counting function. It will receive a card parameter,
so make a card paramenter with the keywords para is the string card.
which complets the part of the task that is: which can be a number or a string

then they ask: count variable
so i set a variable to count

  var count

then comes: The function will then return a string with the current count and the string Bet if the count is positive, or Hold if the count is zero or negative.
so first the if comes
which is suppose to be postive
all postive things are
+1 2, 3, 4, 5, 6
so the codes suppose to print the bet if they are one of the number

  if postive (2, 3, 4, 5, 6)
  print "Bet

and negative is our neutral
(7, 8, 9 10, ‘J’, ‘Q’, ‘K’, ‘A’ )


so if the number are one of those
it suppose to use hold.

return "hold "

para ="card" > 

Why does this have a > at the end? What does that do?
This line has nothing to do with the card parameter.

You are not told to create a count variable. You are told to update the global count variable. You also never use your local count variable, so this line has no effect on the function.

No. “Positive” means greater than zero.

I don’t know what “if they are one of the number” means.

 if postive (2, 3, 4, 5, 6)
  print "Bet

This is not valid code.

No. “Negative” means less than zero.

1 Like

alright round 2
first we change the 1st line it needs to be in the card para meter
postive is greater then zero so >
lesser then zero <
then we need the count variable
and change else if to if else since this is js
i used : https://www.w3schools.com/js/js_comparisons.asp to make sure i got the lesser then and greater then :3

if ("card" > 0) count = "Bet";

if else ("card" < 0) count = "Hold";
if ("card" > 0) count = "Bet";

if else ("card" < 0) count = "Hold";

You are comparing strings to numbers. You are not using the card parameter at all. You are assigning strings to the count variable. The count variable should be a number. There is nothing in the instructions about the card parameter being positive or negative.

1 Like

It doesn’t. The function already has a card parameter:

function cc(card) { // in this line the word "card" is the function parameter

]

the instructions tell you what it could be passed in.
This card parameter could have 13 different values, depending on the value you need to change the already existing count variable, but the count variable shoudl always stay a number, and you need to change it only by raising it by 1 or lowering it by 1

1 Like

so as i understand it thnx to cowwy
the codes need to do:

2 : count = 1 [ 2, 3, 4, 5, 6 ] + 1
4 : count = 2 [ 2, 3, 4, 5, 6 ] + 1
8 : count = 2 [ 7, 8, 9 ] + 0
J : count = 1 [ 10, J, Q, K, A ] - 1
3 : count = 2
return value is…
count = 2 [positive number]

2 Bet

to hard.
which lessons should i retake?

do you mean that it is too hard to put as code?

well, you need to review comparisons between values, and how to execute code depending on a condition (you have lerneded if/else if/else and switch statements)

1 Like

yep yup i got no clue what to even begin with…

thanks i will review them

Tell us what’s happening:
As far as I get the lesson
This is what I must do
If one of the numbers are

[ 2, 3, 4, 5, 6 ] + 1
[ 7, 8, 9 ] + 0
[ 10, J, Q, K, A ] - 1

They also need a card parameter
and a count variable

I revieuwd this: https://www.w3schools.com/js/js_if_else.asp
and: https://www.w3schools.com/js/js_comparisons.asp

Your code so far


var count = 0;

function cc(card) {
 // Only change code below this line
if (card == 2, 3, 4, 5, 6) {
 count = +1;
} 
else if (card == 7, 8, 9) {
 count = +0;
} 
else (card == 10, 'J', 'Q', 'K', 'A') {
 count = -1;
}

 // 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');

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.2 Safari/605.1.15.

Challenge: Counting Cards

Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/counting-cards

Hi!

Yes, that’s the logic. However, there’s no need to do anything for 7, 8 and 9, since there is no real change.

Now, in regards to Your code, that’s not quite right. I mean, if (card == 2, 3, 4, 5, 6) will not work (maybe it’s pseudo code, in which case would be ok).

I can think of 3 ways to solve this:

Hope it helps :slight_smile:

1 Like

Yes for sure thank man

1 Like

remember that you need to raise the value by one or lower it by one, you are assigning the values +1/0/-1 instead

1 Like

This is not valid syntax. You cannot put a comma separated list after an equality operator.

1 Like

Okay so array’s have:
includes() this is like a boolean and returns either true our false same goes with Boolean
valueToFind this means it will look for a certain value
looked further into them and they all give an output of either true our false
i need to add numbers how is this going to help? if i only get true/false?

u say it is to solve with an array but how?

What I meant is, using arrays you can have the numbers sorted like this:

const array1 = [2, 3, 4, 5, 6];
const array2 = [10, 'J', 'K', 'Q', 'A'];

if (array1.includes(theCard)) {
  // Increment count
else if (array2.includes(theCard)) {
  // Decrement count
}

Of course, this is not the only option, it just gives you more choices to do the what’s asked :slight_smile:.

1 Like

Thanks for clarifying that one up