From ab5301151e064a395410efc0f198f1406f94ca37 Mon Sep 17 00:00:00 2001 From: Robert Flach Date: Fri, 7 Jan 2022 16:38:29 -0600 Subject: [PATCH] Fixed 2 bugs. 1 yes and no both restarted the game 2. zero is supposed to skip the third card but was treated as an invalid bet. 1. In trying as keep as close to the spirit of the original game as possible, there is no handling for an invalidly low number. A zero input prints "chicken" and skips the third card and starts over with 2 new initial cards. 2. After the wad is blown, anything but a yes answer to the "Try again" question ends the game --- 01_Acey_Ducey/javascript/aceyducey.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/01_Acey_Ducey/javascript/aceyducey.js b/01_Acey_Ducey/javascript/aceyducey.js index 8bf5e9e1..9969ebbf 100644 --- a/01_Acey_Ducey/javascript/aceyducey.js +++ b/01_Acey_Ducey/javascript/aceyducey.js @@ -90,19 +90,23 @@ async function main() { print('\nWHAT IS YOUR BET? '); bet = parseInt(await input(), 10); let minimumRequiredBet = 0; - if (bet > minimumRequiredBet) { + if (bet >= minimumRequiredBet) { if (bet > availableDollars) { print('SORRY, MY FRIEND, BUT YOU BET TOO MUCH.'); print(`YOU HAVE ONLY ${availableDollars} DOLLARS TO BET.`); } else { validBet = true; } - } else { - // Does not meet minimum required bet - print('CHICKEN!!'); - print(''); } } + if (bet == 0) + { + // User chose not to bet. + print('CHICKEN!!'); + print(''); + // Don't draw a third card, draw a new set of 2 cards. + continue; + } print('\n\nHERE IS THE CARD WE DREW: '); print(getCardValue(cardThree)); @@ -127,7 +131,7 @@ async function main() { print(''); print(''); - if (isValidYesNoString(tryAgainInput)) { + if (isValidYesString(tryAgainInput)) { availableDollars = 100; } else { print('O.K., HOPE YOU HAD FUN!');