Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
  <title>Number Pyramid - v1</title>
</head>
<body>
  <div id="workarea" >
  </div>
</body>
</html>
 
$(document).ready(function () {
  console.log("starting");
  var workarea=$("#workarea");
  var table=$("<table class='pyramid'/>");
  var num=1;
  for (var i = 1; i<=4;i++) {
    var row=$("<tr/>");
    table.append(row);
    for (var j=1;j<=7;j++) {
      var column=$("<td/>");
      
      if (j>4-i && j<=7-(4-i)) {
        column.html(num);
        column.addClass("occupied");
        num++;
      }
      row.append(column);
    }
  }
  for (var i = 3; i>=1;i--) {
     row=$("<tr/>");
    table.append(row);
    for (var j=1;j<=7;j++) {
       column=$("<td/>");
      
      if (j>4-i && j<=7-(4-i)) {
        column.html(num);
        column.addClass("occupied");
        num++;
      }
      row.append(column);
    }
  }  
  console.log("table");
  workarea.append(table);
})
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
kkleokrishpro
0viewers