Question: Write a program that allows the user to enter Pos magic numbers. Pos magic square is a two-dimensional array of positive integers in which the
Write a program that allows the user to enter Pos magic numbers.
Pos magic square is a two-dimensional array of positive integers in which the following is true:
? The number of rows equals the number of columns.
? Every row, column, and the two diagonals add up to the same number.
o The web page must have a table that has three rows and three columns.
o Allow the user to enter values for each cell.
o Store the values in a two-dimensional array named RichardMagic and determine if it is Pos magic square.


Even if all the rows, colums, and diagnols add up to the same number my program will continue to give a wrong answer. Help please!
var RichardMagic = new Array(3)
for (var i=0; i
RichardMagic[i] = new Array(3)}
function enterNumbers(){
for (var row=0; row
for(var col=0; col
var rowNumber = row+1; var colNumber = col+1;
RichardMagic[row][col] = prompt("Enter a number for row "+rowNumber+", column "+colNumber+":", "");
var ID = "r"+rowNumber+"c"+colNumber;
document.getElementById(ID).innerHTML = RichardMagic[row][col];}}}
function checkForMagicSquare(){
var magic = false;
var sum = 0;
for (var col=0; col
sum = sum + RichardMagic[0][col];}
var rowSum = 0;
for (var i=1; i
for (var j=0; j
rowSum = rowSum + RichardMagic[i][j];
if (rowSum != sum){
magic = false;
break;}}}
var sum_diagonal = 0;
if (magic){
for (var i=0; i
for (var j=0; j
if (i==j)
sum_diagonal += RichardMagic[i][j];
if (sum_diagonal != sum){
magic = false;}}
if (magic){
sum_diagonal = 0;
for (var i=0; i
for (var j=0; j
if ((i+j) == 2)
sum_diagonal += RichardMagic[i][j];
if (sum_diagonal != sum){
magic = false;}}
if (magic == true){document.getElementById("result").innerHTML = "Wow! This is a magic square";}
else {document.getElementById("result").innerHTML = "Sorry, your square is not a magic square";}}
Kung Fu Panda Po Magic Square.
Richard will check if the numbers form a magic square.
A magic square exists when all the rows, columns and diagonals of a square add up to the same number.
| Result: | ||
Richard Ricardo's Kung Fu Panda Po Magic Square Richard will check if the numbers form a magic square. A magic square exists when all the rows, columns, and diagonals of a square add up to the same number. Enter Po's magic numbers 2 3 4 5 6 7 8 9 Check if it is a magic square Sorry, your square is not a magic square Result
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
