Why is such thing happening please help me out!

I have passed the challenge but when is checked the console.log(cc(7)) it showed me 2 Bet which is wrong. As per my code, it should show me 0 Hold.

please tell me if I am wrong.

   **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":

if(count > 0){
 return count + " Bet";
}else if(count <= 0){
 return count + " Hold";
 return "Change Me";
 // Only change code above this line

cc(2); cc(3); console.log(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/89.0.4389.90 Safari/537.36.

Challenge: Counting Cards

Link to the challenge:

Hi @meetb ,

cc(7) on its own (as per your code) will give 0 Hold. But, you have written cc(2) and cc(3) before it. These 2 lines are updating your count variable. Hence, the output you get is 2 Hold.

This variable is updated twice after you call these functions.

1 Like

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