# DUDE CARD COUNTING - BASIC JAVASCRIPT

CARD COUNTING - BASIC JAVASCRIPT

Hello, can someone explain this solution to the card counting exercise, I don’t understand how a string is compared or evaluated with a number as shown in the function: we can see that in the arguments that are passed to the function there are some letters I don’t understand how this function works, how the program compares a string with a number in the ‘if’, the exercise was approved with this code, but I have that doubt, I appreciate the explanation.

``````let count = 0;

function cc(card) {
// Change only the code below this line
if (card <= 6)
count++;
else if (card >= "10")
count--;
return count + (count > 0 ? 'Bet' : 'Hold');
}

// Change only the code above this line

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

Its easier to explain if you show us the code you wrote so we can compare.

That code doesn’t work. It has a number of things wrong with it. Where did you find it?

This code was given to me by the freecodecamp platform, as a solution to the exercise, it was fully approved, but I did not understand how it works.

the exercise is called “card counting” it is in the algorithms and javascript data structure course, this code was given to me by the freecodecamp platform, as a solution to the exercise, it was fully approved, but I did not understand how it works.

This isn’t a valid solution.

What part of the instructions got you stuck when you were trying to write your own solution?

I know the challenge having completed it myself and also helped others who were stuck on it. I’d be happy to help you too, if you’re trying to solve it?

I don’t know where you got the ‘solution’ which you posted above but it definitely doesn’t work, for a number of reasons.

Here’s the link to the challenge for anyone who needs it:

I am looking at the freeCodeCamp challenge guide and the answer you posted is not listed in the guide here

I am not sure where you got this but it is not the correct answer.

I would suggest not looking anymore at this answer because it won’t be helpful to you.

If you need help with this challenge, then we would be happy to help you with the answer you came up with

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