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>
 
 var num=1;
 var tablesize=15;
 var maxi=(tablesize -1)/2 +1;
$(document).ready(function () {
  console.log("starting");
  var workarea=$("#workarea");
  var table=$("<table class='pyramid'/>");
  for (var i = 1; i<=tablesize;i++) {
    renderrow(table,(i<=maxi)?i:(tablesize-i+1));
  }
  console.log("table");
  workarea.append(table);
});
function renderrow(table,i) {
    var column;
    var row=$("<tr/>");
  
    table.append(row);
    for (var j=1;j<=tablesize;j++) {
      column=$("<td/>");
      
      if (j>maxi-i && j<=tablesize-(maxi-i)) {
        column.html(num);
        column.addClass("occupied");
        num++;
      }
      row.append(column);
    }  
}
Output

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

Dismiss x
public
Bin info
kkleokrishpro
0viewers