Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Counting Cards
- // @mhpoblet
- var count = 0;
- function cc(card) {
- // Only change code below this line
- if (card >= 2 && card <= 6) {
- count++; // this is correct/nice! we want to adjust the count variable per card value received.
- // for cards 2 through 6, this does this nicely :) . we need to make the appropriate
- // adjustment for the other cases.
- return count + " Bet"; // ok, let's handle the result/return/s outside of the conditional.
- // this means that we take the rerun/s & count manipulation out of
- // the if/else statement.
- // the only thing we want to accomplish with the conditional is the
- // handling of the count variable, which needs to be calculated
- // (or adjusted five times) based on the card values received.
- } else if (card >= 7 && card <=9) {
- return count + " Hold";
- } else {
- count--;
- return count + " Hold";
- }
- // here, at the conclusion of the conditional iterations, we should have our final count variable. we
- // can now handle the logic & output/return. we can use another conditional (if/else, if you want to) to
- // evaluate the card value being a) positive, or b) zero or negative.
- // as return inside of a conditional are sometimes an issue, we can use a variable assignment (of hold, bet) inside
- // the conditional. once we have the desired assignment to the variable count, we can provide the output (count and betting
- // action).
- return "Change Me";
- // Only change code above this line
- }
- // Add/remove calls to test your function.
- // Note: Only the last will display
- cc(10);cc(2);cc(2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement