Basic JavaScript - Counting Cards

Even though i did solve the problem, i m still confused in visualizing how. I dont fully understand why count is returned with the string instead of the card. My attempts with switch statements failed primarily because i was stuck on how to end with the default, i checked the hints and hint 3 was very confusing on how switch and if statements are combined. My solution is guess work. :pensive

Your code so far

let count = 0;

function cc(card) {
  // Only change code below this line
if (card == 2 || card == 3 || card == 4 || card == 5 || card == 6) {
} else if (card == 10 || card == 'J' || card == 'Q' || card == 'K' || card == 'A') {
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 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Basic JavaScript - Counting Cards

Link to the challenge:

Well, you wrote this code.

return count + " Bet";

What makes you expect card to be returned with that statement?

1 Like

My thought then was that the card value determined if the count will increment or decrement as they were both being compared, so it should be the value returned with the string matching the condition. When this failed on multiple attempts i just used count instead , there was no epiphany just a “what if i tried this could just as well not work” but it did work and didn’t understand why!

While returning the card value works too, the challenge is specifically asking for the count value.

1 Like

The function will then return a string with the current count and the string Bet if the count is positive, or Hold if the count is zero or negative.

Gotta match the requirements.

In this case, returning the last card isn’t useful. Returning the current count along with the advice “Hold” or “Bet” is useful.

1 Like

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