Skip to content

Instantly share code, notes, and snippets.

@KnowledgeMC
Created October 14, 2016 16:08
Show Gist options
  • Save KnowledgeMC/dcd818a61a8ecbb72cd2e3c0cef6a074 to your computer and use it in GitHub Desktop.
Save KnowledgeMC/dcd818a61a8ecbb72cd2e3c0cef6a074 to your computer and use it in GitHub Desktop.
Gist of most challenging code from Project 1
var whoWon = function(){
var dealerScore = calcScore(dealerCards);
var playerScore = calcScore(playerCards);
if (playerScore === 21 && dealerScore != 21){
console.log("21! Player Wins!");
window.alert("21! Player Wins!");
} else if (playerScore > 21){
console.log("Player Busts! Dealer Wins!");
window.alert("Player Busts! Dealer Wins!");
} else if (dealerScore === 21 && playerScore != 21){
console.log("21! Dealer Wins!");
window.alert("21! Dealer Wins!");
} else if (playerScore > dealerScore && playerScore <= 21){
console.log("Player Wins!");
window.alert("Player Wins!");
} else if (dealerScore > playerScore && dealerScore <= 21){
console.log("Dealer Wins!");
window.alert("Dealer Wins!");
} else if (dealerScore > 21 && playerScore <=21){
console.log("Dealer Busts! Player Wins!");
window.alert("Dealer Busts! Player Wins!");
} else if(dealerScore === playerScore){
console.log("It's a Push!");
window.alert("It's a Push!");
}
render();
};
function cardRenderPlayer(){
for(var i =0; i < playerCards.length; i++){
$(playerArray[i]).css({'display': 'inline-block'});
$(playerArray[i]).removeClass("back-red");
$(playerArray[i]).addClass(playerCards[i].cssName);
}
};
//Couldn't have written this without help from Ezra
function Card(cssName) {
this.cssName = cssName;
if (cssName.length === 3) {
this.value = parseInt(cssName.slice(1))
} else if (cssName.indexOf("A") > -1) {
this.value = 11;
} else {
this.value = 10;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment