<input type="button" value="render" id="button"/>
<script>
document.getElementById('button').onclick=function(){
var i=16,
vals=[];
while(0<i-- && (!vals.length || vals[vals.length-1]!==null))
vals.push(prompt('Введите число',i));
var values=[],
sum=function(a){
return a.reduce(function(t,c){
return +c+t;
},0);
};
vals.forEach(function(num,i){
(values[i=Math.floor(i/4)]=(values[i]||[])).push(num);
});
var html='<table>'+values.sort(function(a,b){
return sum(b)-sum(a);
}).map(function(row){
return '<tr>'+row.map(function(num){
return '<td>'+num+'</td>';
}).join("\n")+'</tr>';
}).join("\n")+'</table>';
document.write(html);
};
</script>