Java script counting cards

Tell us what’s happening:
Where am I doing wrong?

var count = 0;

function cc(card) {

  // Only change code below this line

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";}

  

  // Only change code above this line

}

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


**Your code so far**
      
```js

var count = 0;

function cc(card) {
// Only change code below this line
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";}


// 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 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36.

Challenge: Counting Cards

Link to the challenge:

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";<<you forgot to insert space before Bet
} else { return count + "Hold";}<<you forgot to insert space before Hold

Let me know if it works

Thanks, but it has space before Bet and Hold

in javascript string is set between ’ ’ and " "
example:

let test1 = 'I'+ 'like'+ 'to'+ 'code'
console.log(test1)//Iliketocode

this is different from:

let test2 = 'I'+ ' like' + ' to' + ' code'
console.log(test2)//I like to code

therefore to get the reader to recognize the space, you need to put it within your single or double quotation mark

so for your case:

return count + "Bet"// 1Bet

instead of the required 1 Bet

Ok this is like this:
{return count + “Bet”;

} else { return count + “Hold”;}

return count single space + single space “Bet”;
} else { return count single space + single space “Hold”;}

No semi colon after }

Thanks

if you write 3 + "Bet" it results in "3Bet"

a space is not added automatically if it’s not present between the quotes

you could also write return count+"Hold" and you get the same exact result because spaces outside strings have often no meaning and are useful just for readability

1 Like

not really try:

if(count>0){
return count + " Bet";
} else{
return count + " Hold";
}

Oh got it, from your last reply, thanks again

1 Like

Got it from Coder A; it should be + " Bet"
Thank you too

yup yup
welcome.
Happy coding

Thanks, and Happy coding to you too

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

You can post solutions that invite discussion (like asking how the solution works, or asking about certain parts of the solution). But please don’t just post your solution for the sake of sharing it.
If you post a full passing solution to a challenge and have questions about it, please surround it with [spoiler] and [/spoiler] tags on the line above and below your solution code.

1 Like

Thank you for information and suggestion.

But if you would read at the beginning of the question, I believe you wouldn’t sent me this email. Question/Answer: if the poster would know where is the problem of his/her question, he/she wouldn’t post the whole solution that he/she figured out which is not workable.

Thank you