I have attended every class, and the teacher wont help on homework
assigned outside of class. I already have tried on numerous occasions
only to fall up short. I will submit the latest attempt in hopes that
it can be dissected and corrected.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<!-- HW 6 -->
<HEAD>
<TITLE>Jonathan Riehm CIS 201-01 HW 6</TITLE>
<SCRIPT LANGUAGE = "JavaScript">
var holder,
num,
userScore,
compScore,
x,
y,
flag;
compScore = 0;
userScore = 0;
holder = new Array ( 9 );
flag = new Array ( 9 );
for (var i=0; i <=8; i++) {
holder [i] = Math.floor( 1 + Math.random() * 9 );
flag [i] = 0;
}
document.writeln(holder);
document.writeln(flag);
window.alert("User turn. Click on a cell inside the table");
function test (num) {
if (num == 1){
cell1.innerText = holder [0];
flag[num] = 1;
}
else if (num == 2) {
cell2.innerText = holder [1];
flag[num] = 1;
}
else if (num == 3) {
cell3.innerText = holder [2];
flag[num] = 1;
}
else if (num == 4) {
cell4.innerText = holder [3];
flag[num] = 1;
}
else if (num == 5) {
cell5.innerText = holder [4];
flag[num] = 1;
}
else if (num == 6) {
cell6.innerText = holder [5];
flag[num] = 1;
}
else if (num == 7) {
cell7.innerText = holder [6];
flag[num] = 1;
}
else if (num == 8) {
cell8.innerText = holder [7];
flag[num] = 1;
}
else if (num == 9) {
cell9.innerText = holder [8];
flag[num] = 1;
}
}
for (var j = 1; j <= 9; j++) {
if ( j%2 != 0) {
window.alert("User turn. Click on a cell inside the table");
y = num - 1
userScore = (userScore + holder [y]);
}
else {
x = Math.floor( 1 + Math.random() * 9);
if (flag [x] = 1) {
j--;
}
else compScore = (compScore + holder [y]);
}
}
if (userScore > compScore)
window.alert("User Wins!");
else window.alert("Computer Wins!");
</SCRIPT>
</HEAD>
<BODY>
<TABLE BORDER="1" WIDTH = "100%">
<TR>
<TD ONCLICK = "test (1)"><P ID = "cell1">Click me!</P></TD>
<TD ONCLICK = "test (2)"><P ID = "cell2">Click me!</P></TD>
<TD ONCLICK = "test (3)"><P ID = "cell3">Click me!</P></TD>
</TR>
<TR>
<TD ONCLICK = "test (4)"><P ID = "cell4">Click me!</P></TD>
<TD ONCLICK = "test (5)"><P ID = "cell5">Click me!</P></TD>
<TD ONCLICK = "test (6)"><P ID = "cell6">Click me!</P></TD>
</TR>
<TR>
<TD ONCLICK = "test (7)"><P ID = "cell7">Click me!</P></TD>
<TD ONCLICK = "test (8)"><P ID = "cell8">Click me!</P></TD>
<TD ONCLICK = "test (9)"><P ID = "cell9">Click me!</P></TD>
</TR>
</TABLE>
</BODY>
</HTML>
Received on Mon May 1 03:41:40 2006