Can Anyone Explain How The Conditions and Blocks of Codes Inside The If Else Statements Work ?
I understand simple if else and ternary but not this, it looks like ternary operator if (card == 2 || card == 3 || card == 4 || card == 5 || card == 6) // Is it because there are 5 elements inside?
cc(2); cc(3); cc(4); cc(5); cc(6); // It displays 5 Bet
How does this else if display "0 Hold" when I call the function with cc(7); cc(8); cc(9); ?
When I called the cc (card) function with cc(2); cc(3); it displays " 2 Bet " and when I called cc(card) function with cc(2); cc(3); cc(4); cc(5); cc(6); it displays " 5 Bet “, so in this case " 5 Bet " is equal to " count += 1 ? Meaning “1” become 5 and displays " 5 Bet” in the result?
Can you add all the code to codepen and paste a link here? It’s important to see how you are calling these functions and what the value of count is in various places.
My understanding is the value of count should NOT be reset.
This is meant to be a card-counting script, for blackjack. It needs to maintain the value of count based on all previous cards, not just the one being currently passed.
The count +1; is what increments the count up by 1. In counting cards, the player keeps track of which cards have been dealt with a count variable. A high value for count means the player should bet, as the odds of winning are higher. See the console below to observe how the count variable changes as I pass each card through the function.
console.log(cc(2)); // outputs 1 Bet
console.log(cc(3)); // outputs 2 Bet
console.log(cc(7)); // still outputs 2 Bet. Should this output " 0 Hold " ? or Is it because the counting jumps to card == 7 from card == 3?
console.log(cc(10)); still outputs 1 Bet. Should this output " - 1 Hold " ?
console.log(cc(‘K’)); // outputs " 0 Hold "; Should this output " - 2 Hold " ?
console.log(cc(‘Q’)); // outputs " - 1 Hold "; Should this output " - 3 Hold " ?
Because if that’s the first time you called the function, count started at 0 and hasn’t been changed by other cards yet. count is a global variable, which is overridden by the cc() function each time it gets called.