<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
div.t{border:1px solid #8B4513;width:4.7%;text-align:center;font-size:.8em;}
.test{margin:0;padding:0;display:flex;flex-wrap:wrap;justify-content:center; width: 800px;}
.red{color:#F00;font-weight:bold}
</style>
</head>
<body>
<script>
var n = 20, m = 20;
var arr = [];
for (var j = 0; j < n; j++){
for (var i = 0; i < m; i++){
if(!arr[i]) arr[i] = [];
arr[i][j] = 0;
if(j==0 && (i==10 || i==11)){
arr[i][j] = 120;
}
if(j > 0){
if(i-1 >= 0 && i+1 < m)
arr[i][j] = 0.5 * (arr[i-1][j-1] + arr[i+1][j-1])
else if(i-1 < 0)
arr[i][j] = 0.5 * (0 + arr[i+1][j-1])
else
arr[i][j] = 0.5 * (arr[i-1][j-1] + 0)
}
}
}
var d= document.createElement('div');
d.className = 'test';
document.body.appendChild(d);
for(var i=0;i<m;i++){
for(var j=0;j<n;j++){
cls = 't';
arr[i][j] && (arr[i][j] = arr[i][j].toFixed(2).replace(/\.?0+$/,'')) && (cls = 't red');
var div = document.createElement('div');
div.className = cls;
div.appendChild(document.createTextNode(arr[i][j]));
d.appendChild(div);
}
}
</script>
</body>
</html>