Basic JavaScript - Counting Cards

Tell us what’s happening:
Hello,
I don’t really understand the problem here.
What kind of sequence is there, when the input into the function is always one number or just a single character a a string?
How should I continue from there?
As you can see my code is not what the problem wants as solution, so I kindly ask for a guidance on how to approach this?

Thank you so much!

  **Your code so far**
let count = 0;

function cc(card) {
// Only change code below this line
let stakes = [' Bet',' Hold'];
switch (card) {
  case (card === 2 || 3 || 4 || 5 || 6):
    return (count+=1) + stakes[0];
}

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

Challenge: Basic JavaScript - Counting Cards

Link to the challenge:

Hi @Arskeliss ,
Hoping you’re good. Coming to the Query - The Premise is this:

  • We’ve 3 categories of cards with specific value attached to them.
    image
  • We’ve to write a function that takes card category type and evaluates point for the player and updates global point variable count. (Note that initial point of the player is set to 0.)
  • It returns a string with points concatenated to it
    Say if my final points is 0 or less than 0, eg. -6 . Function will return -6 Hold
    if my final point is above 0, eg. 7. Function will retur 7 Bet (Read as 7 one space Bet)

How to solve it?

  • If/else Construct
  • Switch Construct

Please feel free to ask anything that might not be clear in my explanation.


Amit Kumar Gupta

So, this above should be the sequence?
It would have been easier to give it as an array.
But, if I take cc(2) as shown above, then the output must be 1 Bet. Am I wrong?

Or should I understand this as the input is cc(2,3,7,'K','A');?

It would have been easier to give it as an array.
But, if I take cc(2);, as shown above, then the output must be 1 Bet

Correct, That would return 1 Bet

It would have been easier to give it as an array.

In Real world We’d batch considering we would like to track the points for every steps. Totally depends on what we’re solving for. We can def. extends if we’d want to.

Coming to the question - It needs to do the function call for each cards
i.e cc(2); cc(3); cc(7); cc('K'); cc('A');

Hint on the existing code:

Summary

This part case (card === 2 || 3 || 4 || 5 || 6) getting short circuited every time leading to wrong results.

I have edited the code and switched to if/else statements, it was weird at first, but I figured that when I check the code in VSCode, I should use console.log, and the results were fine, so in the solution page, I just needed to change the console.log to return keyword.

And it’s solved.

Thanks for pointing out the fault in the code I wrote.

Cheers!

I should use console.log , and the results were fine

Do check on using BreakPoint, It gives better hold on what’s happening inside of your code i.e value / scope / context of a variable/function etc.