Initializing
Liveweave
Web
expand_more
home
Home
data_object
CSS Explorer
arrow_outward
Palette
Color Explorer
arrow_outward
Polyline
Graphics Editor
arrow_outward
outbox_alt
Generative AI
arrow_outward
frame_source
Python Playground
New
arrow_outward
build
Tools
expand_more
restart_alt
Load "Hello Weaver!"
post_add
Generate Lorem ipsum...
code
Format HTML
code_blocks
Format CSS
data_object
Format JavaScript
library_add
Library
expand_more
A
Algolia JS
Animate CSS
Apex Charts JS
B
Bulma CSS
Bootstrap
C
Chart JS
Chartist
Create JS
D
D3
Dojo
F
Foundation
Fullpage JS
G
Granim JS
Google Charts
H
Halfmoon
J
jQuery
M
Materialize
Moment JS
Masonry JS
Milligram CSS
P
Pure CSS
Primer CSS
Popper JS
Pattern CSS
Picnic CSS
R
React JS
Raphael JS
Raisin CSS
S
Semantic UI
Skeleton CSS
Spectre CSS
Tachyons CSS
T
Tailwind
Three JS
U
UI Kit
Vis JS
W
Water CSS
download
Download
expand_more
developer_mode
Download as HTML
folder_zip
Download as .ZIP
cloud_upload
Save
account_circle
Login
settings
Settings
expand_more
14
px
Live mode
Night mode
Line number
Mini map
Word wrap
sync_alt
Reset Settings
smart_display
Run
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Deal test</title> <link rel="stylesheet" href="css/styles.css"> </head> <body onload="deal();"> <div class="mainContent"> <div> <ul> <li id="p1_spades"><span>♠ </span></li> <li id="p1_hearts"><span>♥ </span></li> <li id="p1_diamonds"><span>♦ </span></li> <li id="p1_clubs"><span>♣ </span></li> </ul> </div> <div class="infotext"> <p>How do i sort this baby?<br>From: AKQJ...432</p> </div> </div><!-- mainContent --> <script src="js/script.js"></script> </body> </html>
body { font-size: 1.5em; } p { text-align: center; } li { list-style: none; } .mainContent { border: 1px solid #000; width: 40%; margin: 0 auto; }
var deal = function () { //Player hands var north_hand = []; var east_hand = []; var south_hand = []; var west_hand = []; //Creating the deck var deck = [{'suit': 's', 'value': 'A'}, {'suit': 's', 'value': 'K'}, {'suit': 's', 'value': 'Q'}, {'suit': 's', 'value': 'J'}, {'suit': 's', 'value': 'T'}, {'suit': 's', 'value': '9'}, {'suit': 's', 'value': '8'}, {'suit': 's', 'value': '7'}, {'suit': 's', 'value': '6'}, {'suit': 's', 'value': '5'}, {'suit': 's', 'value': '4'}, {'suit': 's', 'value': '3'}, {'suit': 's', 'value': '2'}, {'suit': 'h', 'value': 'A'}, {'suit': 'h', 'value': 'K'}, {'suit': 'h', 'value': 'Q'}, {'suit': 'h', 'value': 'J'}, {'suit': 'h', 'value': 'T'}, {'suit': 'h', 'value': '9'}, {'suit': 'h', 'value': '8'}, {'suit': 'h', 'value': '7'}, {'suit': 'h', 'value': '6'}, {'suit': 'h', 'value': '5'}, {'suit': 'h', 'value': '4'}, {'suit': 'h', 'value': '3'}, {'suit': 'h', 'value': '2'}, {'suit': 'd', 'value': 'A'}, {'suit': 'd', 'value': 'K'}, {'suit': 'd', 'value': 'Q'}, {'suit': 'd', 'value': 'J'}, {'suit': 'd', 'value': 'T'}, {'suit': 'd', 'value': '9'}, {'suit': 'd', 'value': '8'}, {'suit': 'd', 'value': '7'}, {'suit': 'd', 'value': '6'}, {'suit': 'd', 'value': '5'}, {'suit': 'd', 'value': '4'}, {'suit': 'd', 'value': '3'}, {'suit': 'd', 'value': '2'}, {'suit': 'c', 'value': 'A'}, {'suit': 'c', 'value': 'K'}, {'suit': 'c', 'value': 'Q'}, {'suit': 'c', 'value': 'J'}, {'suit': 'c', 'value': 'T'}, {'suit': 'c', 'value': '9'}, {'suit': 'c', 'value': '8'}, {'suit': 'c', 'value': '7'}, {'suit': 'c', 'value': '6'}, {'suit': 'c', 'value': '5'}, {'suit': 'c', 'value': '4'}, {'suit': 'c', 'value': '3'}, {'suit': 'c', 'value': '2'}]; //Call the shffleDeck function shuffleDeck(deck); //Slice the deck up north_hand = deck.slice(0, 13); east_hand = deck.slice(13, 26); south_hand = deck.slice(26, 39); west_hand = deck.slice(39, 52); console.log(north_hand); //Getting the elements i want to add the cards to var north_spades = document.getElementById('p1_spades'); var north_hearts = document.getElementById('p1_hearts'); var north_diamonds = document.getElementById('p1_diamonds'); var north_clubs = document.getElementById('p1_clubs'); for (var i = 0; i < north_hand.length; i++) { if (north_hand[i].suit == "s") { north_spades.innerHTML += north_hand[i].value; } else if (north_hand[i].suit == "h") { north_hearts.innerHTML += north_hand[i].value; } else if (north_hand[i].suit == "d") { north_diamonds.innerHTML += north_hand[i].value; } else { north_clubs.innerHTML += north_hand[i].value; } } }; // Based on Fisher-Yates algoritm (Shuffle) function shuffleDeck(array) { var m = array.length, t, i; // While there remain elements to shuffle… while (m) { // Pick a remaining element… i = Math.floor(Math.random() * m--); // And swap it with the current element. t = array[m]; array[m] = array[i]; array[i] = t; } return array; }