JSFiddle - React, Tailwind, and code Playground
HTML
<form>
<p><b>Student at Stanford University 2013-2014</b>
</p>
<table id="sdtable">
<thead>
<tr>
<th>Faculty (Subject)</th>
<th>Student 2013</th>
<th>Student 2014</th>
<th>Student 2015</th>
</tr>
</thead>
<tbody>
<tr>
<th>Business</th>
<td>12922</td>
<td>11420</td>
<td>1142</td>
</tr>
<tr>
<th>Earth Sciences</th>
<td>4320</td>
<td>4611</td>
<td>461</td>
</tr>
<tr>
<th>Education</th>
<td>14560</td>
<td>13490</td>
<td>1349</td>
</tr>
<tr>
<th>Engineering</th>
<td>8750</td>
<td>9863</td>
<td>983</td>
</tr>
<tr>
<th>Humanities & Sciences</th>
<td>7819</td>
<td>7219</td>
<td>719</td>
</tr>
<tr>
<th>Medicine</th>
<td>5219</td>
<td>4200</td>
<td>420</td>
</tr>
</tbody>
</table>
</form>
<button onclick="Calculate()">Calculate</button>
<div id="sum">
<div id="Studentt" class="Studentt"></div>
</div>
CSS
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid black;
}
th {
padding: 5px;
text-align: left;
}
td {
padding: 5px;
text-align: right;
}
JavaScript
var ftable = document.getElementById("sdtable");
var i = 0;
var sumFirst = 0;
var sumSecond = 0;
var sumTotal = 0;
function Calculate() {
var rows = ftable.tBodies[0].rows,
header = ftable.tHead.rows[0],
cells = ftable.tBodies[0].rows[0].cells,
years = [];
for (var i = 0; i < rows.length; i++) {
for (var j = 1; j < cells.length; j++) {
if (!years[j]) years[j] = 0;
years[j] += parseInt(rows[i].cells[j].innerHTML);
}
}
sumTotal = years.reduce(function(prev, curr) {
return prev + curr;
}, 0);
var sum = document.getElementById("sum");
sum.innerHTML = '';
for (var j = 1; j < cells.length; j++) {
console.log(header.cells[j])
sum.insertAdjacentHTML('afterbegin', '<p><b>' + header.cells[j].innerHTML + '</b> = ' + years[j] + '</p>');
}
sum.insertAdjacentHTML('beforeend', "<b>Total Student = </b>" + sumTotal);
}