I have created a JavaScript based game, which is based on the card game War. I think I am reusing a lot of my code, but I am not entirely sure what I can really improve. I have a lot of functions, which could probably be improved.Please take a look and give me a review of it. I think I nailed it, but let me know what you think. Also, it is supposed to run on a Node.js server, so basically everything will be authorized through the server, which will check everything through before giving the user input (which prevents faking their total money, their bettings, etc.).Note: Some variables may not be used in the code. That's on purpose (most of them are used) because it is for the future of the project.Also on JSFiddle - To view the actual page Go here! //Each player's deckvar dealerDeck = [];var playerDeck = [];//52 cards = 26 cards leftvar dealerAmountLeft = 26;var playerAmountLeft = 26;//The amount of money and the bet amountvar playerTotal = 40;var betAmount = 0;//Each round, dealerCard and playerCard are set to a random card from their deck//warDealerCards/warPlayercards is a string, which contains 1, 2, then 3 cards seperated by a +var dealerCard, playerCard, warDealerCards, warPlayerCards;//Checks how many cards has been giving when a war has been startedvar warCards = 0;//Whether a war has been started or notvar warStarted = false;//Keeps track of how many times each player has won in a started warvar dealerWarsWon = 0;var playerWarsWon = 0;var warInterval;//Sets a languagevar language = en-GB;//Card classfunction Card(value, name, suit) {    this.value = value;    this.name = name;    this.suit = suit;}//Deck classfunction Deck() {    switch (language) {        case da-DK:            this.suits = ['Hjerter', 'Ruder', 'Spar', 'Klr'];            this.names = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'kngt', 'dronning', 'konge'];            break;        case en-US:            this.suits = ['Hearts', 'Diamonds', 'Spades', 'Clubs'];            this.names = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King'];            break;        case en-GB:            this.suits = ['Hearts', 'Diamonds', 'Spades', 'Clubs'];            this.names = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King'];            break;    }    var cards = [];    for (var s = 0; s < this.suits.length; s++) {        for (var n = 0; n < this.names.length; n++) {            cards.push(new Card(n + 1, this.names[n], this.suits[s]));        }    }    return cards;}//Created a deckvar myDeck = new Deck();function shuffle(o) {    for (var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);    return o;};//Shuffles the deckmyDeck = shuffle(myDeck);//Gives cards to each player (dealer and player)function giveCards(o) {    var count = o.length / 2;    for (i = 0; i < count; i++) {        dealerDeck.push(o.shift(0));        playerDeck.push(o.shift(0));    }    dealerAmountLeft = 26;    playerAmountLeft = 26;}giveCards(myDeck);//Created a DealerCard classfunction DealerCard() {}//Overrides toString() on the dealer card class, which means new DealerCard().toString() will return the suit and nameDealerCard.prototype.toString = function() {    return dealerCard[0].suit +   + dealerCard[0].name;}//Created a PlayerCard classfunction PlayerCard() {}//Overrides toString() on the player card class, which means new PlayerCard().toString() will return the suit and namePlayerCard.prototype.toString = function() {    return playerCard[0].suit +   + playerCard[0].name;}//Call this = Give each player a random card from their deckfunction selectCards() {    dealerCard = dealerDeck.splice(Math.floor(Math.random() * dealerDeck.length), 1);    playerCard = playerDeck.splice(Math.floor(Math.random() * playerDeck.length), 1);    //Ace is the highest/best card. King is second highest card. King's value == 13, therefore set Ace's value to 14 (this is hacky)    if (dealerCard[0].value == 1) {        dealerCard[0].value = 14;    }    if (playerCard[0].value == 1) {        playerCard[0].value = 14;    }}//Sets a warfunction setWar() {    warStarted = true;    $(#dealer).text();    $(#player).text();    startWar();    warInterval = setInterval(startWar, 1000);}//Starts a warfunction startWar() {    //Only run this while the war is still going    if (warCards < 3) {        selectCards();        if (warCards == 0) {            warDealerCards = new DealerCard().toString();            warPlayerCards = new PlayerCard().toString();            $(#dealer).append(warDealerCards);            $(#player).append(warPlayerCards);        } else {            warDealerCards +=  +  + new DealerCard().toString();            warPlayerCards +=  +  + new PlayerCard().toString();            $(#dealer).text(warDealerCards);            $(#player).text(warPlayerCards);        }        checkWinner();        warCards++;        dealerAmountLeft--;        playerAmountLeft--;        console.log(War cards:  + warCards);    } else if (warCards == 3) {        warWinner();        warCards = 0;        warStarted = false;        $(#bet).show();    }}//Does stuff like creating history, when the winner has been foundfunction warWinner() {    if (playerWarsWon >= 2 && warCards == 3) {        console.log(PLAYER WON!!!);        createHistory(#12345, you, warDealerCards, warPlayerCards);        $(#winner).text(Player won!).addClass(winnerFound);        setPlayerTotal(betAmount, false);    } else if (dealerWarsWon >= 2 && warCards == 3) {        setPlayerTotal(betAmount, true);        createHistory(#12345, dealer, warDealerCards, warPlayerCards);        $(#winner).text(Dealer won!).addClass(winnerFound);        console.log(DEALER WON!!!);    }    clearInterval(warInterval);    warStated = false;}//Checks who wins each card draw. Pretty self-explanatoryfunction checkWinner() {    if (warStarted) {        if (dealerCard[0].value < playerCard[0].value) {            $(#winner).text(Player wins!);            playerWarsWon++;        } else if (dealerCard[0].value > playerCard[0].value) {            $(#winner).text(Dealer wins!);            dealerWarsWon++;        } else if (dealerCard[0].value == playerCard[0].value) {            $(#winner).text(TIME TO WAR);            $(#warButtons).show();            $(#bet).hide();            $(#deal).hide();        }    } else {        warDealerCards = new DealerCard().toString();        warPlayerCards = new PlayerCard().toString();        if (dealerCard[0].value < playerCard[0].value) {            $(#winner).text(Player wins!);            createHistory(#12345, you, warDealerCards, warPlayerCards);            setPlayerTotal(betAmount, false);        } else if (dealerCard[0].value > playerCard[0].value) {            $(#winner).text(Dealer wins!);            createHistory(#12345, dealer, warDealerCards, warPlayerCards);            setPlayerTotal(betAmount, true);        } else if (dealerCard[0].value == playerCard[0].value) {            $(#winner).text(TIME TO WAR);            $(#warButtons).show();            $(#bet).hide();            $(#deal).hide();        }    }}//When the deal button has been pressed, start dealing the cards$(#deal).on(click, function() {    console.log(War cards:  + warCards);    console.log(Amount of player cards:  + playerAmountLeft);    if (betAmount > playerTotal) {        alert(BET AMOUNT TOO HIGH);        playerTotal(0);        updateBetAmount();    } else if (playerTotal > 0) {        selectCards();        dealerAmountLeft--;        playerAmountLeft--;        $(#dealer).text(new DealerCard().toString());        $(#player).text(new PlayerCard().toString());        checkWinner();        if (playerAmountLeft == 0) {            console.log(GAME DONE! STARTING NEW);            myDeck = new Deck();            myDeck = shuffle(myDeck);            giveCards(myDeck);        }    } else {        alert(OUT OF MONEY);    }});//Sets the bet amount when one of the amounts has been clicked$(.amount).on(click, function() {    setBetAmount($(this).attr(data-amount), false);    $(.amount).removeClass(selected);    $(this).addClass(selected);});//Resets the bet amount$(#reset).on(click, function() {    setBetAmount(betAmount, true);});//Checks which button has been pressed (forfeit, continue or double)//Used to set the bet amount$(#warButtons button).on(click, function() {    if ($(this).attr(data-id) == forfeit) {        setPlayerTotal(betAmount * 0.9, true);    } else if ($(this).attr(data-id) == continue) {        setWar();    } else if ($(this).attr(data-id) == double) {        setBetAmount(betAmount, false);        setWar();    }    $(#deal).show();    $(#warButtons).hide();});//Function to update the bet amountfunction updateBetAmount() {    $(#betAmount).text(Bet Amount:  + betAmount);}//Function to update the player totalfunction updatePlayerTotal() {    $(#totalAmount).text(Total:  + playerTotal);}//Function to set the bet amount. Takes 2 arguments. n is the amount and neg determines if it should deduct or add the amountfunction setBetAmount(n, neg) {    if (neg) {        betAmount += -Math.abs(parseFloat(n))    } else {        betAmount += parseFloat(n);    }    if (betAmount >= playerTotal) {        betAmount = playerTotal;    }    updateBetAmount();}//Sets the player total after winning or losing function setPlayerTotal(n, neg) {    if (neg) {        playerTotal += -Math.abs(parseFloat(n));    } else {        playerTotal += parseFloat(n);    }    updatePlayerTotal();}//Adds an element to the history on the left side of the screenfunction createHistory(id, winner, dealer, player) {    $(#historyHeader).after('<div class=historyGame>ID: <span class=historyId></span>' + id + ' - Winner: <span class=historyWinner>' + winner + '</span> - Bet amount: <span class=historyAmount>' + betAmount + '</span><br /><span class=historyDealer>Dealer: <span class=historyDealerInner>' + dealer + '</span></span><br /><span class=historyPlayer>You: <span class=historyPlayerInner>' + player + '</span></span></div>');    if (winner == you) {        $(.historyGame:first .historyPlayerInner).addClass(historyWinner);    } else {        $(.historyGame:first .historyDealerInner).addClass(historyWinner);    }    if ($(.historyGame).length > 1) {        $(.historyGame:first).append(<hr>);    }}updateBetAmount();updatePlayerTotal();#game {    width: 800px;    height: 100%;    margin: 0 auto;    text-align: center;}#deal {    width: 150px;    height: 70px;    font-size: 30px;}#dealer,#player {    height: 300px;    font-size: 30px;    font-weight: bold;}#winner {    height: 100px;    font-size: 40px;}#warButtons {    display: none;    -webkit-user-select: none;    -moz-user-select: none;    -khtml-user-select: none;    -ms-user-select: none;}#warButtons button {    width: 100px;    height: 40px;    font-size: 16px;}.amount {    width: 50px;    height: 50px;    border-radius: 25px;    line-height: 50px;    background-color: #CCC;    display: inline-block;    cursor: pointer;    -webkit-user-select: none;    -moz-user-select: none;    -khtml-user-select: none;    -ms-user-select: none;}#betAmount {    -webkit-user-select: none;    -moz-user-select: none;    -khtml-user-select: none;    -ms-user-select: none;}.amount:hover {    background-color: #CCA;}.selected {    background-color: #CCA;}.winnerFound {    font-size: 80px !important;}#history {    width: 400px;    height: 200px;    overflow-y: scroll;    overflow-x: hide;    background-color: #CCC;    float: left;    margin: 0;    padding: 6px;}#history hr {    border: 1px solid black;    margin: 20px 0px 20px 0px;}#historyHeader {    height: 30px;    width: 400px;    background-color: darkgrey;    padding: 0;    margin: 0;    text-align: center;    font-size: 28px;    line-height: 30px;}.historyGame:nth-child(2) {    margin-top: 10px;}.historyWinner {    color: lime !important;}<script src=https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js></script><div id=history>    <div id=historyHeader>History</div></div><div id=game>    <div id=betAmount></div>    <div id=totalAmount></div>    <div id=dealer></div>    <div id=winner></div>    <div id=player></div>    <div id=bet>        <button id=reset>Reset</button>        <div class=amount data-amount=1.00>1</div>        <div class=amount data-amount=2.00>2</div>        <div class=amount data-amount=2.50>2.5</div>        <div class=amount data-amount=5.00>5</div>    </div>    <div id=warButtons>        <button data-id=forfeit title=Forfeit the game and get 90% of your bet back>Forfeit (0.9x)</button>        <button data-id=continue title=Continue the game with original bet>Continue (1x)</button>        <button data-id=double title=Continue the game, but double the bet>Double (2x)</button>    </div>    <button id=deal>Deal</button></div>
War card game which includes betting money as well
javascript;jquery;playing cards