Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <section class="deck" v-scope="DeckOfCards()" @vue:mounted="shuffleDeck">
  
  <section class="controls">
    <button @click="drawCard">Draw Card ({{cardsLeft}} remaining)</button>
    <button  @click="shuffleDeck">Reshuffle Deck</button>

    <h2>The value of the hand is {{handValue}}</h2>
    <p v-for="card in hand" >{{cardAsText(card)}}</p>
  </section>
  
  <ul class="hand">
    <li v-for="card in hand" class="card" v-scope="Card(card)" :class="{red:isRed}"></li>
  </ul>
  
</section>

<template id="card">
  <section class="tl">
    <article class="tl-rank">{{rank}}</article>
    <article class="tl-suit" v-html="suitHTMLCharacter"></article>
  </section>
  <section class="md">
    <article class="m-suit" v-html="suitHTMLCharacter"></article> 
  </section>
  <section class="br">
    <article class="br-rank">{{rank}}</article>
    <article class="br-suit" v-html="suitHTMLCharacter"></article>
  </section>
</template>
              
            
!

CSS

              
                *, *::before, *::after { box-sizing:border-box }

body {
	margin:10px;
  background-color:#598e3c;
}

.controls {
  color:white;
}

button {
  width:100%;
  min-height:50px;
  border-radius:0;
  border:none;
  cursor:pointer;
  margin-block:2px;
  
  &:hover {
    background-color:gray;
    color:white;
  }
}

.deck {
  display:grid;
  grid-template-columns: 280px 1fr;
}

.hand {
  padding:20px;
  list-style:none;
  display:grid;
  grid-template-columns: repeat( auto-fill, 136px );
  grid-auto-rows: 170px;
  gap:10px;
}

.card {
  background-color:#fff;
  box-sizing:content-box;
  padding:5px 8px;
  box-shadow:0px 2px 3px 1px #444;
  border-radius:5px;
  
  aspect-ratio: 12 / 16;
  width:120px;
  
  display:grid;
  grid-template-columns: 1fr 2fr 1fr;
  grid-template-rows: 1fr 2fr 1fr;
  
  grid-template-areas:
    "tl . ."
    ". md ."
    ". . br";
  
  .tl { 
    grid-area: tl;
    justify-self:start;
    text-align:center;
  }
  
  .md { 
    grid-area: md; 
    justify-self:center;
    font-size:68px;
  }
  
  .br { 
    grid-area: br; 
    justify-self:end;
    transform: rotate(180deg); 
    text-align:center;
  }
  
  &.red {
    color:red;
  }

}


              
            
!

JS

              
                import { createApp } from 'https://unpkg.com/petite-vue?module'

const DeckOfCards = () => {
  
  return {
    deck: undefined,
    hand:[],
    drawCard() {
      if( this.deck.length ) {
        this.hand.push( this.deck.splice( Math.random() * this.deck.length >> 0, 1 )[0] );
      }
    },
    get cardsLeft() {
      return this.deck?.length;
    },
    get handValue() {
      return this.hand.reduce( (sum, v) => {
        return sum + v.value;
      }, 0);
    },
    cardAsText(card) {
      return `The ${card.rank} of ${card.suit}`;
    },
    shuffleDeck() {
      this.hand = [];
      this.deck = this.makeDeck();
    },
    makeDeck() {
    
      const suits = [ "hearts", "diamonds", "clubs", "spades" ];
      const ranks = [ "A", 2, 3, 4, 5, 6, 7, 8, 9, 10, "J", "Q", "K" ];
      const values = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10 ];

      return suits.map( suit => {
        return [
          ...ranks.map( (rank,i) => {
            return {
              suit,
              rank,
              value: values[i]
            }
          })
        ];
      }).flat();
    }
  }
}

const Card = ({suit, rank, value}) => {
  return {
    $template: '#card',
    suit,
    rank,
    value,
    get isRed() {
      return ["diamonds", "hearts"].includes(this.suit);
    },
    get isBlack() {
      return ["clubs", "spades"].includes(this.suit);
    },
    get suitHTMLCharacter() {
      return this.suit === "diamonds" ? "&diams\;" : `&${this.suit.toLowerCase()}\;`;
    },
    get asText() {
      return `The ${rank} of ${suit}`;
    }
  }
}

createApp({DeckOfCards, Card}).mount();
              
            
!
999px

Console