var f = prompt('Vals 1!', '2,7,6').split(','),
s = prompt('Vals 2!', '9,5,1').split(','),
t = prompt('Vals 3!', '4,3,8').split(',');
alert(isMagic([f, s, t]));
function isMagic(matrix) {
for (var i = 0; i < matrix.length; i++) {
var e = matrix[i];
for (var j = 0; j < e.length; j++) {
e[j] = +e[j];
}
}
var diagonals = [
[],
[]
],
rows = [],
cols = [
[],
[],
[]
];
for (var i = 0; i < matrix.length; i++) {
var e = matrix[i],
rSum = 0;
for (var j = 0; j < e.length; j++) {
rSum += e[j];
}
rows.push(rSum);
diagonals[0].push(e[i]);
cols[0].push(e[0]);
cols[1].push(e[1]);
cols[2].push(e[2]);
}
var count = 1;
for (var i = 0; i < matrix.length; i++) {
var e = matrix[i]
diagonals[1].push(e[e.length - count]);
count++;
}
for (var i = 0; i < cols.length; i++) {
var e = cols[i],
s = 0;
for (var j = 0; j < e.length; j++) {
s += e[j];
}
cols[i] = s;
}
for (var i = 0; i < diagonals.length; i++) {
var e = diagonals[i],
s = 0;
for (var j = 0; j < e.length; j++) {
s += e[j];
}
diagonals[i] = s;
}
if (diagonals[0] == diagonals[1] && rows[0] == rows[1] && rows[1] == rows[2] && cols[0] == cols[1] && cols[1] == cols[2]) {
return 'Magic square';
};
return false;
};