Basic JavaScript - Counting Cards

Tell us what’s happening:

As i m writting code i wanted to test first the output, and I am confused, why first time count is 1 and other four times is 2 when i console.log the count, It gives me

1
2
2
2
2

? should it increase each time? like 0 became 1 and 1 became 2 and so on?

Your code so far

let count = 0;

function cc(card) {
switch(card){
  case 2: 
  case 3:
  case 4:
  case 5:
  case 6:
    count ++;
    break
}
console.log(count)
return count;
  // 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/118.0.0.0 Safari/537.36

Challenge Information:

Basic JavaScript - Counting Cards

1 Like

Hello @mahassan :wave:t5:
If the argument is a value in one of the cases, count gets incremented by 1. Therefore, only the following function calls will trigger count to be incremented while the rest won’t.

1 Like

Hi, Sorry I didn’t understand what u mean

1 Like

The value of card is used to determine which case is executed in the switch-case block. The cases available are; 2, 3, 4, 5, 6. If the value of card is either of these numbers, count++ will be executed. If the value of card is not any of those numbers, count++ will not be executed

2 Likes

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