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

              
                <!--
/======== A  L O V I N G L Y  C R A F T E D ============================\
\  __   __   __   __    __   ______   ______   __                       /
/ /\ `-.\ \ /\ \ /\ `-./  \ /\  __ \ /\  __ \ /\ \                      \
\ \ \ \-.  \\ \ \\ \ \-./\ \\ \  __< \ \  __ \\ \ \___                  /
/  \ \_\\`\_\\ \_\\ \_\-\ \_\\ \_____\\ \_\ \_\\ \____\   _| _ _. _  _  \
\   \/_/ \/_/ \/_/ \/_/  \/_/ \/_____/ \/_/\/_/ \/____/  (_|(-_)|(_)| ) /
/================================================================ _) ===\
\============================================ http://nickbrombal.com ===/
-->

<div id="wrapper">
  <h1>A Game of Dabs</h1>
  <table id="card">
    <tr>
      <td id="cell0"></td>
      <td id="cell1"></td>
      <td id="cell2"></td>
      <td id="cell3"></td>
      <td id="cell4"></td>
    </tr>
    <tr>
      <td id="cell5"></td>
      <td id="cell6"></td>
      <td id="cell7"></td>
      <td id="cell8"></td>
      <td id="cell9"></td>
    </tr>
    <tr>
      <td id="cell10"></td>
      <td id="cell11"></td>
      <td id="cell12"></td>
      <td id="cell13"></td>
      <td id="cell14"></td>
    </tr>
    <tr>
      <td id="cell15"></td>
      <td id="cell16"></td>
      <td id="cell17"></td>
      <td id="cell18"></td>
      <td id="cell19"></td>
    </tr>
    <tr>
      <td id="cell20"></td>
      <td id="cell21"></td>
      <td id="cell22"></td>
      <td id="cell23"></td>
      <td id="cell24"></td>
    </tr>
  </table>
  <div id="menu">
    <div id="scoreboard">
      <p class="title">ROWS</p>
      <p class="score"><span id="scoreRow">0</span>/5</p>
      <p class="title">COLUMNS</p>
      <p class="score"><span id="scoreCol">0</span>/5</p>
      <p class="title">DIAGONALS</p>
      <p class="score"><span id="scoreDiag">0</span>/2</p>
    </div>
    <button class="cardFunction" id="newCard">NEW CARD</button>
    <button class="cardFunction" id="cleanCard">CLEAR DABS</button>
    <div id="palette">
      <p>DAB COLOR</p>
      <button class="dabSelect" id="dabRed"></button>
      <button class="dabSelect" id="dabBlue"></button>
      <button class="dabSelect" id="dabYellow"></button>
      <button class="dabSelect" id="dabGreen"></button>
      <button class="dabSelect" id="dabPurple"></button>
      <button class="dabSelect" id="dabOrange"></button>
      <button class="dabSelect" id="dabBlack"></button>
      <button class="dabSelect" id="dabRandom">?</button>
    </div>
  </div>
  <div id="credit"><a href="http://nickbrombal.com/">A Nimbal Design, 2013</a></div>
</div>

              
            
!

CSS

              
                @import "compass/css3";

@import url(https://fonts.googleapis.com/css?family=Roboto:400,700);

* { margin: 0; padding: 0; border: 0; outline: 0; }

body {
  background: #444444 url("http://nickbrombal.com/images/bg_pixel-grey.jpg") repeat fixed;
}

#wrapper {
  margin: 0 auto;
  width: 560px;
}

h1 {
  margin-top: 10px;
  font: 30px roboto;
  text-align: center;
  color: #FFF;
}

#card {
  position: absolute;
  margin: 0 auto;
  border-spacing: 10px;
  border-collapse: separate;
  text-align: center;
  color: #FFF;
  td {
    padding: 10px;
    height: 80px;
    width: 80px;
    background: #777;
    font: 14px arial;
    cursor: pointer;
    &:hover {
      @include box-shadow(inset 0 0 35px #BBB);
      @include transition-duration(.25s);
    }
  }
  .dabbedRed    { background: #FF0000; }
  .dabbedBlue   { background: #0000FF; }
  .dabbedYellow { background: #E6E607; }
  .dabbedGreen  { background: #008000; }
  .dabbedPurple { background: #800080; }
  .dabbedOrange { background: #FFA500; }
  .dabbedBlack  { background: #000000; }
}

#menu {
  position: relative;
  left: 560px;
  width: 100px;
  height: 540px;
  margin-top: 10px;
  #scoreboard {
    height: 200px;
    width: 100px;
    background: rgba(34,34,34,0.6);
    font: 12px roboto;
    text-align: center;
    color: #FFF;
    .title { padding-top: 9px; letter-spacing: 1px; }
    .score { font-size: 30px; }
  }
  .cardFunction {
    margin-top: 10px;
    height: 45px;
    width: 100px;
    background: rgba(34,34,34,0.6);
    font: 12px/45px roboto;
    color: #FFF;
    &:hover {
      background: rgba(34,34,34,1);
      @include transition-duration(.25s);
    }
  }
  #palette {
    margin-top: 10px;
    height: 220px;
    background: rgba(34,34,34,0.6);
    font: 12px/28px roboto;
    text-align: center;
    color: white;
    .dabSelect {
      float: left;
      border-radius: 24px;
      margin: 0 0 4px 4px;
      height: 44px;
      width: 44px;
      vertical-align: top;
      &:hover { border: 3px solid #FFF; }
    }
    #dabRed    { background: #FF0000; }
    #dabBlue   { background: #0000FF; }
    #dabYellow { background: #E6E607; }
    #dabGreen  { background: #008000; }
    #dabPurple { background: #800080; }
    #dabOrange { background: #FFA500; }
    #dabBlack  { background: #000000; }
    #dabRandom { background: #FFFFFF; font: 20px roboto; }
    .dabActive { border: 3px solid #AAA; }
  } 
}

#credit {
  margin-top: 10px;
  width: 100%;
  font: 12px roboto;
  letter-spacing: 2px;
  text-shadow: -1px -1px #888;
  text-align: center;
  a { 
    text-decoration: none; 
    color: #111; 
    &:hover { text-shadow: 1px 1px #888; }
  }
}
              
            
!

JS

              
                $(document).ready(function() {
  // Array containing all of the potential square content and their descriptions, separated by "::".
  var squares = [
    "Filler00::Filler content for testing purposes",
    "Filler01::Filler content for testing purposes",
    "Filler02::Filler content for testing purposes",
    "Filler03::Filler content for testing purposes",
    "Filler04::Filler content for testing purposes",
    "Filler05::Filler content for testing purposes",
    "Filler06::Filler content for testing purposes",
    "Filler07::Filler content for testing purposes",
    "Filler08::Filler content for testing purposes",
    "Filler09::Filler content for testing purposes",
    "Filler10::Filler content for testing purposes",
    "Filler11::Filler content for testing purposes",
    "Filler12::Filler content for testing purposes",
    "Filler13::Filler content for testing purposes",
    "Filler14::Filler content for testing purposes",
    "Filler15::Filler content for testing purposes",
    "Filler16::Filler content for testing purposes",
    "Filler17::Filler content for testing purposes",
    "Filler18::Filler content for testing purposes",
    "Filler19::Filler content for testing purposes",
    "Filler20::Filler content for testing purposes",
    "Filler21::Filler content for testing purposes",
    "Filler22::Filler content for testing purposes",
    "Filler23::Filler content for testing purposes",
    "Filler24::Filler content for testing purposes"
  ];
  var randomDab = ['dabbedRed','dabbedBlue','dabbedYellow','dabbedGreen','dabbedPurple','dabbedOrange','dabbedBlack'];
  var isDabbed = ['cell12'];
  var bingoRow = [];
  var bingoCol = [];
  var bingoDiag = [];
  var dabColor;
  
  // Function to shuffle/randomize array content
  function shuffle(v) {
    for (var j, x, i = v.length; i; j = parseInt(Math.random() * i, 10), x = v[--i], v[i] = v[j], v[j] = x);
    return v;
  }
  // Function to clear all dabs from the card
  function cleanCard() {
    $('td').removeClass();
    isDabbed = [];
    bingoRow = [];
    bingoCol = [];
    bingoDiag = [];
    $('#scoreRow').html(bingoRow.length);
    $('#scoreCol').html(bingoCol.length);
    $('#scoreDiag').html(bingoDiag.length);
  }
  // Function to fill the card with randomized square entries
  function fillCard() {
    cleanCard();
    shuffle(squares);
    for ( i = 0; i < 25; i++ ) {
      var squareName = squares[i].substr(0,squares[i].indexOf("::"));
      var squareDesc = squares[i].substr(squares[i].indexOf("::")+2,squares[i].length);
      $('#cell'+i).html(squareName).attr('title', squareDesc);
    }
  }
  // Function to give the customary free center dab
  function freeDab() {
    isDabbed.push('cell12');
    if ( dabColor == 'random' ) {
      $('#cell12').addClass(randomDab[Math.floor(Math.random()*randomDab.length)]).html('Freebie!').attr('title', ""); 
    } else {
      $('#cell12').addClass(dabColor).html('Freebie!').attr('title', "");
    }
  }
  // Function to check for multiple values within an array
  function containsAll(needles, haystack) { 
    for (var i = 0 , len = needles.length; i < len; i++) {
      if ($.inArray(needles[i], haystack) == -1) return false;
    }
    return true;
  }
  // Function to check for bingos (by searching the isDabbed array for the right sequences of cells) then save them to the bingo array
  function bingoCheck() {
    // Check rows (cells 0-4, 5-9, 10-14, 15-19, and 20-24)
    for ( i = 0; i < 21; i += 5 ) {
      // If all of a row's cells are in the isDabbed array, and if that row isn't already in the bingo array, add it
      if (containsAll(["cell"+i,"cell"+(i+1),"cell"+(i+2),"cell"+(i+3),"cell"+(i+4)], isDabbed)) {
        if ($.inArray("row"+i,bingoRow) == -1) {
          bingoRow.push("row"+i);
          $('#scoreRow').html(bingoRow.length);
          alert("BINGO! You scored a row! Don't stop now!");
        }
      // If all of a row's cells are no longer in the isDabbed array, and if that row is already in the bingo array, remove it
      } else {
        if ($.inArray("row"+i,bingoRow) !== -1) {
          bingoRow.splice( $.inArray("row"+i,bingoRow), 1 );
          $('#scoreRow').html(bingoRow.length);
        }
      }
    }
    // Check columns (cells 0-20, 1-21, 2-22, 3-23, and 4-24)
    for ( i = 0; i < 5; i++ ) {
      // If all of a column's cells are in the isDabbed array, and if that column isn't already in the bingo array, add it
      if (containsAll(["cell"+i,"cell"+(i+5),"cell"+(i+10),"cell"+(i+15),"cell"+(i+20)], isDabbed)) {
        if ($.inArray("col"+i,bingoCol) == -1) {
          bingoCol.push("col"+i);
          $('#scoreCol').html(bingoCol.length);
          alert("BINGO! You scored a column! Keep it up!");
        } 
      // If all of a column's cells are no longer in the isDabbed array, and if that column is already in the bingo array, remove it
      } else {
        if ($.inArray("col"+i,bingoCol) !== -1) {
          bingoCol.splice( $.inArray("col"+i,bingoCol), 1 );
          $('#scoreCol').html(bingoCol.length);
        }
      }
    }
    // Check forward diagonal (cells 0, 6, 12, 18, and 24)
    if (containsAll(["cell0","cell6","cell12","cell18","cell24"], isDabbed)) {
      if ($.inArray("diag0",bingoDiag) == -1) {
        bingoDiag.push("diag0");
        $('#scoreDiag').html(bingoDiag.length);
        alert("Bingo! You scored a diagonal! Nice moves!");
      }
    } else {
      if ($.inArray("diag0",bingoDiag) !== -1) {
        bingoDiag.splice( $.inArray("diag0",bingoDiag), 1 );
        $('#scoreDiag').html(bingoDiag.length);
      }
    }
    // Check backward diagonal (cells 4, 8, 12, 16, and 20)
    if (containsAll(["cell4","cell8","cell12","cell16","cell20"], isDabbed)) {
      if ($.inArray("diag4",bingoDiag) == -1) {
        bingoDiag.push("diag4");
        $('#scoreDiag').html(bingoDiag.length);
        alert("BINGO! You scored a diagonal! Nice moves!");
      }
    } else {
      if ($.inArray("diag4",bingoDiag) !== -1) {
        bingoDiag.splice( $.inArray("diag4",bingoDiag), 1 );
        $('#scoreDiag').html(bingoDiag.length);
      }
    }
    // Check for a full bingo of all 12 row/column/diagonal combinations
    if ((bingoRow.length == 5) && (bingoCol.length == 5) && (bingoDiag.length == 2)) {
      alert("CONGRATULATIONS - you're a WINNER!");
    }
  }
  // Function to switch the active dabbing color
  function switchDab(color, id) {
    dabColor = color;
    $('.dabSelect').removeClass('dabActive');
    $(id).addClass('dabActive');
  }

  // When clicking a 'td' element, (1) add/remove the 'dabbed' class, (2) add/remove its id to/from the isDabbed array, and (3) run a check for bingos
  $('td').click(function() {
    if ( $.inArray(this.id,isDabbed) !== -1 ) {
      isDabbed.splice( $.inArray(this.id,isDabbed), 1 );
      $(this).removeClass();
    } else {
      isDabbed.push(this.id);
      if ( dabColor == 'random' ) {
        $(this).addClass(randomDab[Math.floor(Math.random()*randomDab.length)]); 
      } else {
        $(this).addClass(dabColor);
      }
    }
    bingoCheck();
  });
  // Refill the card when clicking the "#newCard" button
  $('#newCard').click(function() {
    fillCard();
    freeDab();
  });
  // Clear all dabs from the card when clicking the "#cleanCard" button
  $('#cleanCard').click(function() {
    cleanCard();
  });
  // Switch the dabbing color to red
  $('#dabRed').click(function() {
    switchDab('dabbedRed', this);
  });
  // Switch the dabbing color to blue
  $('#dabBlue').click(function() {
    switchDab('dabbedBlue', this);
  });
  // Switch the dabbing color to green
  $('#dabYellow').click(function() {
    switchDab('dabbedYellow', this);
  });
  // Switch the dabbing color to yellow
  $('#dabGreen').click(function() {
    switchDab('dabbedGreen', this);
  });
  // Switch the dabbing color to purple
  $('#dabPurple').click(function() {
    switchDab('dabbedPurple', this);
  });
  // Switch the dabbing color to orange
  $('#dabOrange').click(function() {
    switchDab('dabbedOrange', this);
  });
  // Switch the dabbing color to black
  $('#dabBlack').click(function() {
    switchDab('dabbedBlack', this);
  });
  // Switch the dabbing color to random
  $('#dabRandom').click(function() {
    switchDab('random', this);
  });
  
  // Initialize the card on page load
  switchDab('dabbedRed', '#dabRed');
  fillCard();
  freeDab();
  
});
              
            
!
999px

Console