Blackjack Game var cards = [ &quot;ace_of_clubs&quot;, &quot;2_of_clubs&quot;, &quot;3_of_clubs&quot;, &quot;4_of_clubs&quot;, &quot;5_of_clubs&quot;, &quot;6_of_clubs&quot;, &quot;7_of_clubs&quot;, &quot;8_of_clubs&quot;, &quot;9_of_clubs&quot;, &quot;10_of_clubs&quot;, &quot;jack_of_clubs&quot;, &quot;queen_of_clubs&quot;, &quot;king_of_clubs&quot;, &quot;ace_of_spades&quot;, &quot;2_of_spades&quot;, &quot;3_of_spades&quot;, &quot;4_of_spades&quot;, &quot;5_of_spades&quot;, &quot;6_of_spades&quot;, &quot;7_of_spades&quot;, &quot;8_of_spades&quot;, &quot;9_of_spades&quot;, &quot;10_of_spades&quot;, &quot;jack_of_spades&quot;, &quot;queen_of_spades&quot;, &quot;king_of_spades&quot;, &quot;ace_of_diamonds&quot;, &quot;2_of_diamonds&quot;, &quot;3_of_diamonds&quot;, &quot;4_of_diamonds&quot;, &quot;5_of_diamonds&quot;, &quot;6_of_diamonds&quot;, &quot;7_of_diamonds&quot;, &quot;8_of_diamonds&quot;, &quot;9_of_diamonds&quot;, &quot;10_of_diamonds&quot;, &quot;jack_of_diamonds&quot;, &quot;queen_of_diamonds&quot;, &quot;king_of_diamonds&quot;, &quot;ace_of_hearts&quot;, &quot;2_of_hearts&quot;, &quot;3_of_hearts&quot;, &quot;4_of_hearts&quot;, &quot;5_of_hearts&quot;, &quot;6_of_hearts&quot;, &quot;7_of_hearts&quot;, &quot;8_of_hearts&quot;, &quot;9_of_hearts&quot;, &quot;10_of_hearts&quot;, &quot;jack_of_hearts&quot;, &quot;queen_of_hearts&quot;, &quot;king_of_hearts&quot;, ]; var players; var list; var currentPlayer = 1; var cardNumber = 2; var player1Score; var player2Score; var player3Score; var player4Score; var player5Score; var scores = [0, 0, 0, 0, 0]; function confirmPlayers() { list = document.getElementById(&quot;numOfPlayers&quot;); players = list.options[list.selectedIndex].value; document.getElementById(&quot;openingText&quot;).style.display = &quot;none&quot;; dealCards(); alert(&quot;Pass device to player 1&quot;); }</p> <pre class="language-nolang"><code> function dealCards() { for (i = players; i &gt; 0; i--) { var player = players - i + 1; playerDiv = document.createElement(&quot;div&quot;) document.body.appendChild(playerDiv) playerDiv.id = &quot;player&quot; + player + &quot;div&quot; playerDiv.style.display = &quot;none&quot; var playerTitle = document.createElement(&quot;h4&quot;); playerTitle.innerHTML = &quot;Player &quot; + player; playerDiv.appendChild(playerTitle) var main1 = document.createElement(&quot;img&quot;); playerDiv.appendChild(main1); imgIndex1 = Math.round(((cards.length - 1) * Math.random())); var main1Src = &quot;Cards/&quot; + cards[imgIndex1] + &quot;.png&quot;; cards.splice(imgIndex1, 1); main1.src = main1Src; main1.width = 195; main1.id = &quot;player&quot; + player + &quot;card1&quot; calculateScore(player, main1.src); var main2 = document.createElement(&quot;img&quot;); playerDiv.appendChild(main2); imgIndex2 = Math.round(((cards.length - 1) * Math.random())); var main2Src = &quot;Cards/&quot; + cards[imgIndex2] + &quot;.png&quot;; cards.splice(imgIndex2, 1); main2.src = main2Src; main2.width = 195; main2.id = &quot;player&quot; + player + &quot;card2&quot; calculateScore(player, main2.src); playerDiv.appendChild(document.createElement(&quot;br&quot;)); playerDiv.appendChild(document.createElement(&quot;br&quot;)); playerDiv.appendChild(document.createElement(&quot;br&quot;)); } document.getElementById(&quot;player1div&quot;).style.display = &quot;inline&quot; document.getElementById(&quot;hit&quot;).style.display = &quot;inline&quot;; document.getElementById(&quot;fold&quot;).style.display = &quot;inline&quot;; } function hits() { cardNumber++; imgIndex = Math.round(((cards.length - 1) * Math.random())); var cardSrc = &quot;Cards/&quot; + cards[imgIndex] + &quot;.png&quot;; currentCard = document.createElement(&quot;img&quot;) currentCard.src = cardSrc; currentCard.width = 195; currentCard.id = &quot;player&quot; + currentPlayer + &quot;card&quot; + cardNumber; document.getElementById(&quot;player&quot; + currentPlayer + &quot;div&quot;).appendChild(currentCard); cards.splice(imgIndex, 1); calculateScore(currentPlayer, currentCard.src); console.log(scores); } function folds() { if (currentPlayer == players) { endGame(); } else { document.getElementById(&quot;player&quot; + currentPlayer + &quot;div&quot;).style.display = &quot;none&quot;; switchPlayer(); } } function switchPlayer() { cardNumber = 2; currentPlayer++; alert(&quot;Pass the device to player &quot; + currentPlayer); document.getElementById(&quot;player&quot; + currentPlayer + &quot;div&quot;).style.display = &quot;inline&quot;; } function endGame() { alert(&quot;The winner is &quot; + &quot;player &quot; + winner() + &quot;!&quot;); } function calculateScore(player, src) { if ((src.charAt(68) == &quot;2&quot;) || (src.charAt(68) == &quot;3&quot;) || (src.charAt(68) == &quot;4&quot;) || (src.charAt(68) == &quot;5&quot;) || (src.charAt(68) == &quot;6&quot;) || (src.charAt(68) == &quot;7&quot;) || (src.charAt(68) == &quot;8&quot;) || (src.charAt(68) == &quot;9&quot;) || (src.charAt(68) == &quot;1&quot;)) { score = parseInt(src.charAt(68), 10); newScore = scores[(player - 1)] + score; scores.splice((player - 1), 1, newScore); } else if (src.charAt(68) == &quot;a&quot;) { newScore = scores[(player - 1)] + 1; scores.splice((player - 1), 1, newScore); } else { newScore = scores[(player - 1)] + 10; scores.splice((player - 1), 1, newScore); } } function winner() { var highest = 0; var winner = 0; for (i = 0; i &lt; scores.length; i++) { if ((scores[i] &lt;= 21) &amp;&amp; (scores[i] &gt; highest)) { highest = scores[i]; winner = i; (console.log(i)); } } filtered = scores.filter(a =&gt; ((a &gt; 0) &amp;&amp; (a &lt;= 21))) console.log(scores) if (filtered.length &lt; 1) { &quot;The dealer wins!&quot; } else { return (winner + 1); } } &lt;/script&gt; </code></pre> <p></head> <body bgcolor="black"> <br> <br> <center><div class="logo"><img src="localhackdaylogo.jpg" width=500></div> <br> <br> <div class="title">blackjack for all</div> <br> <div class="quote">&quot;Who said we want to conform to the norm? Celebrate and embrace our differences.&quot;<br> - Neil Milliken</div> <br> <br> <div class="body">Hey guys! For today&#39;s hackathon, we decided to create a game of blackjack that is free for anyone to play. Our team consisted of lead developer Amir Barkam, assosciate developer Kyle Aganon, and lead designer Sheevam Sharma.</div> <br> <br> <img src="igicon.png" width=50> <br> <br> <br> <br> <table style="width:100%"> <tr> <th><img src="amir.jpg" width=150></th> <th><img src="me.jpg" width=150></th> <th><img src="sheev.jpg" width=150></th> </tr> <tr> <td><div class="insta">@amiralib6</div></td> <td><div class="insta">@kswaganon</div></td> <td><div class="insta">@sheevam_sharma</div></td> </tr> </table> <br></p> <pre class="language-nolang"><code> Hey guys! For today&#39;s hackathon, we decided to create a game of blackjack that is free for anyone to play. Our team consisted of lead developer Amir Barkam, assosciate developer Kyle Agagon, and lead designer Sheevam Sharma. &lt;br&gt; &lt;h1&gt;Blackjack&lt;/h1&gt; &lt;div id=&quot;openingText&quot;&gt; &lt;p&gt;Welcome to the virtual blackjack game! To get started, tell us how many players you would like to have playing!&lt;/p&gt; &lt;h5&gt;Enter the number of players&lt;/h5&gt; &lt;select id=&quot;numOfPlayers&quot;&gt; &lt;option value=&quot;2&quot;&gt;2&lt;/option&gt; &lt;option value=&quot;3&quot;&gt;3&lt;/option&gt; &lt;option value=&quot;4&quot;&gt;4&lt;/option&gt; &lt;option value=&quot;5&quot;&gt;5&lt;/option&gt; &lt;/select&gt; &lt;button onClick=&quot;confirmPlayers()&quot;&gt;Confirm&lt;/button&gt; &lt;/div&gt; &lt;button id=&quot;hit&quot; onClick=&quot;hits()&quot; style=&quot;display: none&quot;&gt;Hit&lt;/button&gt; &lt;button id=&quot;fold&quot; onClick=&quot;folds()&quot; style=&quot;display: none&quot;&gt;Fold&lt;/button&gt; </code></pre> <p></body> </html></p>

Built With

Share this project:

Updates