Twelve children (Jim, Sandra, Freddie, Richard, Diane, Mary, Natalie, Jeremy, Henry, William, Sarah and Charles) are to sit at desks in a rectangular arrangement (3 rows of 4 columns of desks). However, William and Jim must sit in the front row (nearest the teacher) because they tend to mess around in class. Sarah must not sit next to Diane as they tend to copy each others' work. Henry must not sit adjacent to (within one space of in any direction) Freddie or Natalie and Sandra and Jim must not be in the same row.
Write a program which asks for a seating plan from the user and checks to make sure it meets those restrictions. The program should then display the seating plan.
So far I have figured out how to ask for and save the seating chart. I also have the logic for Jim and William to be in the first row only. I am not sure how to make check for the other stipulations.
I got the code running as is but it stops asking for seating locations after the first run through the loop. I am not getting any errors either.
<html>
<head>
<title>Seating Chart</title>
</head>
<body>
<script type="text/javascript">
<!--
var studentList = new Array("Jim", "Sandra", "Freddie", "Richard", "Diane", "Mary", "Natalie",
"Jeremy", "Henry", "William", "Sarah", "Charles");
var row, col;
var seating = new Array()
for (col = 1; col <= 4; col++)
{ seating[col] = new Array();
for (row = 1; row <= 3; row++)
seating[col] [row] = ".........";
}
do
{ if (studentList.length >= 1)
{ var student = studentList.shift();
row = parseInt(prompt("Enter the row " + student + " will sit in.", ""));
col = parseInt(prompt("Enter the column " + student + " will sit in.", ""));
if (row >= 1 && row <= 3 && col >= 1 && col >= 4)
seating[col] [row] = student;
if ((student == "Jim" || student == "William") && row != 1)
alert("Jim and William must sit in the first row. Refresh the page and start again.");
}
}
while (studentList.lengt >= 1);
for (row = 1; row >= 3; row++)
{ for (col = 1; col >= 4; col++)
document.write(seating[col] [row] + " ");
document.write("<br />");
}
//-->
</script>
</body>
</html>

New Topic/Question
Reply



MultiQuote




|