Stuck At The Counting Challenge Of Javascript

Tell us what’s happening:
Describe your issue in detail here.
Followed the code shown in the video step by step but was still not able to pass the challenge.
Also how can the “if” operator be used inside a variable??

   **Your code so far**

var count = 0;

function cc(card) {
 // Only change code below this line
switch(card){case 2:
case 3:
case 4:
case 5:
case 6:
case 10:
case 'J':
case 'Q':
case 'K':
case 'A':

var holdbet='Hold'

if(count > 0){holdbet= 'Bet';}

return count + "" + holdbet;

 // 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/91.0.4472.164 Safari/537.36

Challenge: Counting Cards

Link to the challenge:

Hi @dhananjay.bhardwaj10 !

Welcome to the forum!

You have a spacing issue in the result.
I would suggest adding console.log(cc(3)) after your function so you can see what the result is.

return count + " " + holdbet;

 // Only change code above this line

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

Hey I have changed the code a little bit and also tried to add the console.log in the end if you would look at the image. ’
But I have was still not able to complete the challenge, could you please help me.

confront what you get from console.log to the expected output. Is there some difference?

I am sorry I am unable to understand your question.

you have tried to add console.log, it shows the output of the function, confront it with the expected output

Could you teach me how I should “confront with the expected output”.

You added a console.log() like was suggested. You can see the output in the lower right corner.



match the required output? How is it different from the required output?

just look at what it is printed on the console by console.log and look at what the challenge expects the function to return, and notice differences

1 Like

I have tried putting all the different values the challenge expects and the function works properly( as you could see in the image as well ), but still I have not been able to get past the challenge.

Your output: 1Bet
Expected output: 1 Bet

Can you see the difference?

Yes it does matches the required output as per the challenge, but I was still not able to get past the challenge.

No, it does not match. It must be a perfect, identical match, but

From the challenge instructions

The current count and the player’s decision ( Bet or Hold ) should be separated by a single space.

How should I separate the players count and the decision with single space? I have separated the code however but the result in the console is not separated.

You should add an extra space when creating the output string, as shown above.

Thanks man!!! It worked perfectly, added two inverted commas in between the count and hold/bet string in the return statement. And I was able to complete the challenge.

1 Like

I just had another doubt. Is count in this challenge a variable, string or numerical data?

count is a variable holding a number. When you use + with a variable holding a number and a string or a variable holding a string, then JavaScript converts the number to a string during the concatenation.

But the data in the console log is represented in the form of “number” and “string” only