Skip to content

Commit

Permalink
Fix computer blackjack bug
Browse files Browse the repository at this point in the history
Computer getting blackjack was not recorded properly. Also computer only gets dealt one card at the beginning of the turn. 

// function compare(user_score, computer_score) {
//   if (user_score > 21 && computer_score > 21) {
//     return "You went over. You lose 😀";
//   }

//   if (user_score == computer_score) {
//     return "Draw πŸ™ƒ";
//   } else if (computer_score == 0) {
//     return "Lose, opponent has Blackjack 😱";
//   } else if (user_score == 0) {
//     return "Win with a Blackjack 😎";
//   } else if (user_score > 21) {
//     return "You went over. You lose 😭";
//   } else if (computer_score > 21) {
//     return "Opponent went over. You win 😁";
//   } else if (user_score > computer_score) {
//     return "You win πŸ˜ƒ";
//   } else {
//     return "You lose 😀";
//   }
// }
  • Loading branch information
TheMuellenator authored Jul 9, 2024
1 parent 7cfd803 commit 00d0feb
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ function restart() {
NewLine(logo, false);
for (let i = 0; i < 2; i++) {
user_cards.push(deal_card());
computer_cards.push(deal_card());
}
computer_cards.push(deal_card());

newRound();
}
Expand Down Expand Up @@ -188,17 +188,18 @@ function calculate_score(cards) {
return cards.reduce((partialSum, a) => partialSum + a, 0);
}

// new compare function. Checks for computer blackjack
function compare(user_score, computer_score) {
if (user_score > 21 && computer_score > 21) {
return "You went over. You lose 😀";
}

if (user_score == computer_score) {
return "Draw πŸ™ƒ";
} else if (computer_score == 0) {
if (computer_score == 0) {
return "Lose, opponent has Blackjack 😱";
} else if (user_score == 0) {
return "Win with a Blackjack 😎";
} else if (user_score == computer_score) {
return "Draw πŸ™ƒ";
} else if (user_score > 21) {
return "You went over. You lose 😭";
} else if (computer_score > 21) {
Expand Down

0 comments on commit 00d0feb

Please sign in to comment.